Skip to content

remove flakiness on kafka tests#11972

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
masterfrom
andrea.marziali/kafka-contextswap
Jul 16, 2026
Merged

remove flakiness on kafka tests#11972
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
masterfrom
andrea.marziali/kafka-contextswap

Conversation

@amarziali

Copy link
Copy Markdown
Contributor

What Does This Do

The flaky test was caused by onMessage() calling TEST_WRITER.waitForTraces(1) on the consumer thread. That blocked the same thread that needed to continue and finish the child span. If the root span was finished but the child stayed open for over the 500ms PendingTraceBuffer watchdog window, the trace could be force-flushed early with only the root span. Later, the child span finished and was written separately, producing two 1-span traces instead of one 2-span trace.

The wait was an old leftover used for deterministic ordering, but ordering is no longer needed because the tests now sort traces before asserting.

Motivation

Additional Notes

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@amarziali amarziali added the type: bug fix Bug fix label Jul 16, 2026
@amarziali
amarziali requested review from a team as code owners July 16, 2026 13:45
@amarziali amarziali added tag: no release notes Changes to exclude from release notes tag: flaky test Flaky tests labels Jul 16, 2026
@amarziali
amarziali requested review from ValentinZakharov and removed request for a team July 16, 2026 13:45
@amarziali amarziali added the inst: kafka Kafka instrumentation label Jul 16, 2026

@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

Here are some automated review suggestions for this pull request.

Reviewed commit: 2ff84d2c0e

ℹ️ 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".

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Jul 16, 2026

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 69.73% (+12.55%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 937a1b7 | Docs | Datadog PR Page | Give us feedback!

@datadog-datadog-us1-prod datadog-datadog-us1-prod 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.

Datadog Autotest: FAIL

The PR removes waitForTraces(1) from Kafka test onMessage callbacks, which was causing flakiness by blocking the consumer thread while its span was still open (the span doesn't close until the next hasNext() call after onMessage returns, not during it). Removing the barrier is correct and safe for most tests. However, in "test spring kafka template produce and consume" in both kafka-clients-0.11 and kafka-clients-3.8, the same waitForTraces(1) was also the only synchronization ensuring the parent trace landed at TEST_WRITER[0] before the consumer trace; without it the consumer trace can be written first, making the subsequent TEST_WRITER[0][2] access an IndexOutOfBoundsException. Fixed by replacing it with a sorted snapshot using SORT_TRACES_BY_ID, matching the pattern already used in latestDepTest.

View proposed fix
📊 Validated against 6 scenarios · Open Bits AI session

🤖 Datadog Autotest · Commit 2ff84d2 · What is Autotest? · Any feedback? Reach out in #autotest

@dd-octo-sts

dd-octo-sts Bot commented Jul 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.95 s 13.95 s [-0.7%; +0.6%] (no difference)
startup:insecure-bank:tracing:Agent 12.88 s 12.95 s [-1.3%; +0.2%] (no difference)
startup:petclinic:appsec:Agent 16.40 s 16.79 s [-6.7%; +2.1%] (no difference)
startup:petclinic:iast:Agent 16.78 s 16.84 s [-1.3%; +0.6%] (no difference)
startup:petclinic:profiling:Agent 16.56 s 16.73 s [-2.1%; +0.1%] (no difference)
startup:petclinic:sca:Agent 15.90 s 16.79 s [-11.1%; +0.6%] (unstable)
startup:petclinic:tracing:Agent 15.98 s 16.04 s [-1.4%; +0.7%] (no difference)

Commit: 937a1b73 · 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.

@amarziali

Copy link
Copy Markdown
Contributor Author

@codex review

@pr-commenter

pr-commenter Bot commented Jul 16, 2026

Copy link
Copy Markdown

Kafka / producer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master andrea.marziali/kafka-contextswap
git_commit_date 1784204168 1784211426
git_commit_sha 48bc030 937a1b7
See matching parameters
Baseline Candidate
ci_job_date 1784213047 1784213047
ci_job_id 1865594548 1865594548
ci_pipeline_id 125021919 125021919
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
jdkVersion 11.0.25 11.0.25
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 -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/go/src/github.com/DataDog/apm-reliability/dd-trace-java/platform/src/producer-benchmark/build/tmp/jmh -Duser.country=US -Duser.language=en -Duser.variant -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/go/src/github.com/DataDog/apm-reliability/dd-trace-java/platform/src/producer-benchmark/build/tmp/jmh -Duser.country=US -Duser.language=en -Duser.variant
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.25+9-post-Ubuntu-1ubuntu122.04 11.0.25+9-post-Ubuntu-1ubuntu122.04

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 same

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 937a1b737e

ℹ️ 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".

@pr-commenter

pr-commenter Bot commented Jul 16, 2026

Copy link
Copy Markdown

Kafka / consumer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master andrea.marziali/kafka-contextswap
git_commit_date 1784204168 1784211426
git_commit_sha 48bc030 937a1b7
See matching parameters
Baseline Candidate
ci_job_date 1784212834 1784212834
ci_job_id 1865653693 1865653693
ci_pipeline_id 125021919 125021919
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
jdkVersion 11.0.25 11.0.25
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 -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/go/src/github.com/DataDog/apm-reliability/dd-trace-java/platform/src/consumer-benchmark/build/tmp/jmh -Duser.country=US -Duser.language=en -Duser.variant -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/go/src/github.com/DataDog/apm-reliability/dd-trace-java/platform/src/consumer-benchmark/build/tmp/jmh -Duser.country=US -Duser.language=en -Duser.variant
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.25+9-post-Ubuntu-1ubuntu122.04 11.0.25+9-post-Ubuntu-1ubuntu122.04

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 same

@amarziali

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jul 16, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-07-16 15:20:15 UTC ℹ️ Start processing command /merge


2026-07-16 15:20:21 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 2h (p90).


2026-07-16 15:32:08 UTC 🚨 MergeQueue: This merge request is in error because of DDCI

DDCI pipeline didn't start (sourcing_failed)... Please retry.

DDCI Change Request: 4460576448744691944
You can get help from #ci-infra-support

@amarziali

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jul 16, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-07-16 15:55:59 UTC ℹ️ Start processing command /merge


2026-07-16 15:56:05 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 2h (p90).


2026-07-16 17:03:43 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 48ac26b into master Jul 16, 2026
587 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the andrea.marziali/kafka-contextswap branch July 16, 2026 17:03
@github-actions github-actions Bot added this to the 1.65.0 milestone Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: kafka Kafka instrumentation tag: flaky test Flaky tests tag: no release notes Changes to exclude from release notes type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants