Skip to content

Restore Kafka async consumer commit backlog tracking - #12915

Open
amarziali wants to merge 1 commit into
masterfrom
andrea.marziali/fix-kafka-commit-callback-registration
Open

amarziali wants to merge 1 commit into
masterfrom
andrea.marziali/fix-kafka-commit-callback-registration

Conversation

@amarziali

Copy link
Copy Markdown
Contributor

What Does This Do

The async consumer’s commit callback instrumentation was missing @AutoService, so it was not registered and did not emit DSM commit backlog metrics.

This change registers the existing instrumentation and declares its required helpers and context stores. It also passes the metadata context store from advice into the callback wrapper, because InstrumentationContext.get() must be resolved in advice rather than called from a helper. The callback-based tracking design remains unchanged.

Tests verify callback delivery during poll, synchronous commit, and close. The null-group and missing-consumer-info cases now assert both callback behavior and emitted backlog metrics.

Motivation

Additional Notes

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@amarziali amarziali added the type: bug fix Bug fix label Oct 16, 2026
@amarziali
amarziali requested review from a team as code owners October 16, 2026 15:48
@amarziali amarziali added the inst: kafka Kafka instrumentation label Oct 16, 2026
@amarziali
amarziali requested review from jordan-wong and removed request for a team October 16, 2026 15:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T15:56:01.951945Z 58d9872 PR opened
🔒 Security Review ✅ Completed 2026-10-16T15:52:35.870067Z 58d9872 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review


P1 Badge Cover callback-free and synchronous commits

When the async consumer uses commitAsync() without a callback, Kafka delegates with a null callback and returns without calling enqueueUserCallbackInvocation; commitSync likewise completes through its commit future without invoking this method (Apache Kafka source). Because this instrumentation matches only enqueueUserCallbackInvocation, neither of these common successful commit paths emits a backlog update. Instrument a common successful commit-completion path rather than only user callback registration.

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


// new - this instrumentation is completely new.
// the purpose of this class is to provide us with information on consumer group and cluster ID
@AutoService(InstrumenterModule.class)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Skip backlog updates for failed async commits

When commitAsync(..., callback) completes exceptionally, Kafka 3.8 still enqueues the callback with the requested offsets and a non-null exception (Apache Kafka source). Registering this instrumentation activates DDOffsetCommitCallback, which ignores that exception and reports every requested offset as committed, under-reporting backlog precisely when a rebalance, timeout, or broker error prevented the commit. Preserve callback delivery, but only call trackBacklog when the completion exception is null.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this is known - complete overhaul is not the scope here

Comment on lines +19 to +22
new DDOffsetCommitCallback(
callback,
kafkaConsumerInfo,
InstrumentationContext.get(Metadata.class, MetadataState.class));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Track backlog before invoking the application callback

When an application callback throws or mutates the supplied offsets map, DDOffsetCommitCallback invokes it before reading that map, so a successful commit can produce no backlog update or an update based on application-modified data. Because this change makes that wrapper live for every async callback, perform the Datadog bookkeeping before invoking the application callback, or otherwise isolate it with finally and an unmodified offset snapshot.

Useful? React with 👍 / 👎.

@amarziali amarziali Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also known. It does not look offensive - up to concerned team to open a follow up

@amarziali amarziali added the tag: override groovy enforcement Override the "Enforce Groovy Migration" check label Oct 16, 2026

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

The newly registered callback wrapper reports requested offsets even when an asynchronous commit fails, allowing rejected commits to understate consumer lag.

Open Bits AI session

🤖 Bits Code Review · Commit 58d9872


// new - this instrumentation is completely new.
// the purpose of this class is to provide us with information on consumer group and cluster ID
@AutoService(InstrumenterModule.class)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Skip backlog updates for failed async commits

When an asynchronous commit fails, Kafka delivers the requested offsets with a non-null exception. Registering this instrumentation activates DDOffsetCommitCallback, which forwards the application callback but then reports those offsets through trackBacklog regardless of the exception. Rejected commits can therefore advance the reported committed position and understate consumer lag. Preserve callback delivery, but skip backlog reporting when the commit failed.

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

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 59.46% (-0.39%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 58d9872 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.89 s 13.93 s [-1.0%; +0.4%] (no difference)
startup:insecure-bank:tracing:Agent 12.83 s 12.92 s [-1.6%; +0.2%] (no difference)
startup:petclinic:appsec:Agent 17.15 s 17.06 s [-0.2%; +1.3%] (no difference)
startup:petclinic:iast:Agent 16.96 s 16.81 s [-0.0%; +1.8%] (no difference)
startup:petclinic:profiling:Agent 16.72 s 16.20 s [-1.3%; +7.7%] (no difference)
startup:petclinic:sca:Agent 17.11 s 17.03 s [-0.3%; +1.3%] (no difference)
startup:petclinic:tracing:Agent 16.05 s 16.13 s [-1.5%; +0.5%] (no difference)

Commit: 58d98720 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@pr-commenter

pr-commenter Bot commented Oct 16, 2026

Copy link
Copy Markdown

Kafka / producer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master andrea.marziali/fix-kafka-commit-callback-registration
git_commit_date 1791799930 1792165386
git_commit_sha 134a70e 58d9872
See matching parameters
Baseline Candidate
ci_job_date 1792166989 1792166989
ci_job_id 2147444376 2147444376
ci_pipeline_id 145322921 145322921
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
jdkVersion 11.0.31 11.0.31
jmhVersion 1.36 1.36
jvm /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
jvmArgs -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost *.localhost
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-6el97fiu 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-6el97fiu 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics.

See unchanged results
scenario Δ mean throughput
scenario:not-instrumented/KafkaProduceBenchmark.benchProduce same
scenario:only-tracing-dsm-disabled-benchmarks/KafkaProduceBenchmark.benchProduce same
scenario:only-tracing-dsm-enabled-benchmarks/KafkaProduceBenchmark.benchProduce unsure
[+74.896op/s; +3584.690op/s] or [+0.059%; +2.844%]

@pr-commenter

pr-commenter Bot commented Oct 16, 2026

Copy link
Copy Markdown

Kafka / consumer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master andrea.marziali/fix-kafka-commit-callback-registration
git_commit_date 1791799930 1792165386
git_commit_sha 134a70e 58d9872
See matching parameters
Baseline Candidate
ci_job_date 1792167066 1792167066
ci_job_id 2147444379 2147444379
ci_pipeline_id 145322921 145322921
cpu_model Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz
jdkVersion 11.0.31 11.0.31
jmhVersion 1.36 1.36
jvm /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
jvmArgs -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost *.localhost
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-wzd2qhp4 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-wzd2qhp4 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics.

See unchanged results
scenario Δ mean throughput
scenario:not-instrumented/KafkaConsumerBenchmark.benchConsume same
scenario:only-tracing-dsm-disabled-benchmarks/KafkaConsumerBenchmark.benchConsume same
scenario:only-tracing-dsm-enabled-benchmarks/KafkaConsumerBenchmark.benchConsume unsure
[+1196.775op/s; +9762.838op/s] or [+0.763%; +6.225%]

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: kafka Kafka instrumentation tag: override groovy enforcement Override the "Enforce Groovy Migration" check type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants