Skip to content

fix(tracer): eliminate IEEE 754 flakes in TestSamplingDecision#4530

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
dario.castane/ktlo/fix-ieee-754-flakes
Mar 13, 2026
Merged

fix(tracer): eliminate IEEE 754 flakes in TestSamplingDecision#4530
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
dario.castane/ktlo/fix-ieee-754-flakes

Conversation

@darccio

@darccio darccio commented Mar 12, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Four assertions in TestSamplingDecision were updated:

Fixed denominators (three cases): assert.InDelta(t, 0.8, float64(n)/1000, 0.15) is equivalent to assert.InDelta(t, 800, n, 150). Operating on integers eliminates the division and any rounding entirely.

Dynamic denominator (one case): assert.InDelta(t, 0.5, float64(a)/float64(b), 0.15) cannot be trivially scaled because b varies. Instead the tolerance range [0.35, 0.65] is expressed as exact integer inequalities by multiplying through by 20 (since 0.35 = 7/20 and 0.65 = 13/20):

assert.GreaterOrEqual(t, 20*singleSpans, 7*denom)
assert.LessOrEqual(t,   20*singleSpans, 13*denom)

All integer values involved are well within the range where float64 conversion is exact (< 2^53), so testify's internal float64 comparison is lossless.

Motivation

TestSamplingDecision had four assert.InDelta calls that compared a float64 ratio (computed via division) against an expected value with a tolerance. When the actual sample count landed exactly on the boundary, IEEE 754 floating-point arithmetic produced a result that exceeded the tolerance by one ULP, causing spurious test failures.

The canonical example: keptSpans = 650 with float64(650)/float64(1000) = 0.65. The mathematical value |0.8 - 0.65| = 0.15 is exactly at the tolerance boundary, but the IEEE 754 result is 0.15000000000000002, which fails assert.InDelta(..., 0.15).

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • New code is free of linting errors. You can check this by running make lint locally.
  • New code doesn't break existing tests. You can check this by running make test locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • All generated files are up to date. You can check this by running make generate locally.

Unsure? Have a question? Request a review!

@darccio
darccio requested a review from a team as a code owner March 12, 2026 17:01
@darccio darccio added team:apm-go AI Assisted AI/LLM assistance used in this PR (partially or fully) labels Mar 12, 2026
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Mar 12, 2026

Copy link
Copy Markdown

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 55.78%

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 5557b5e | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@codecov

codecov Bot commented Mar 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.17%. Comparing base (aa5518d) to head (4268687).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

see 429 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pr-commenter

pr-commenter Bot commented Mar 12, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-03-12 17:19:27

Comparing candidate commit 4268687 in PR branch dario.castane/ktlo/fix-ieee-754-flakes with baseline commit aa5518d in branch main.

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

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

@darccio

darccio commented Mar 12, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

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

Comment thread ddtrace/tracer/tracer_test.go
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 0957c7c into main Mar 13, 2026
230 of 235 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the dario.castane/ktlo/fix-ieee-754-flakes branch March 13, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Assisted AI/LLM assistance used in this PR (partially or fully) mergequeue-status: done team:apm-go

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants