Skip to content

fix(ci-visibility): avoid Go FailNow teardown#4717

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
feat/go-ci-visibility-failnow-teardown
May 5, 2026
Merged

fix(ci-visibility): avoid Go FailNow teardown#4717
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
feat/go-ci-visibility-failnow-teardown

Conversation

@tonyredondo

Copy link
Copy Markdown
Member

What does this PR do?

Prevents Go CI Visibility from shutting down the tracer when a test or benchmark calls FailNow.

testing.T.FailNow and testing.B.FailNow stop the current test goroutine via runtime.Goexit; they do not end the whole test process. The previous CI Visibility wrappers and Orchestrion advice called ExitCiVisibility() from those paths, which could close the span pipeline mid-package and drop later test spans, retry attempts, and cleanup-created spans.

This PR removes the premature teardown from:

  • gotesting.T.FailNow
  • gotesting.B.FailNow
  • Orchestrion instrumentation of testing.common.FailNow

The real process teardown paths are left unchanged: M.Run, signal handling, panic/re-panic paths, benchmark panic finalization, retry re-panic, and close actions still call ExitCiVisibility().

It also adds regression coverage for direct wrappers and Orchestrion-instrumented tests, including fatal assertions, retries, benchmarks, and cleanup spans created after FailNow. No new dependency is introduced; module files are unchanged.

Motivation

A customer reported that when any Go test called FailNow, Fatal, Fatalf, or require.*, subsequent tests in the package were silently missing from CI Visibility and ATR retry spans were not reported.

The root cause was that CI Visibility treated FailNow like a process exit, but Go only stops the current test or benchmark. Closing CI Visibility there loses spans that are created later in the same process.

Testing

  • go test ./internal/civisibility/integrations/gotesting/failnow -count=1
  • go test ./internal/civisibility/integrations/gotesting/... -count=1
  • cd internal/orchestrion/_integration && go run github.com/DataDog/orchestrion go test ./civisibility -count=1
  • cd internal/orchestrion/_integration && go run github.com/DataDog/orchestrion go test ./civisibility_failnow -count=1
  • cd internal/orchestrion/_integration && go run github.com/DataDog/orchestrion go test ./civisibility_failnow_retry -count=1
  • cd internal/orchestrion/_integration && go run github.com/DataDog/orchestrion go test ./civisibility_failnow_benchmark -run '^$' -bench . -benchtime=1x -count=1
  • go test ./internal/orchestrion/_integration/civisibilitytest
  • git diff --check
  • Verified go.mod and go.sum are unchanged in both the root module and Orchestrion integration module.

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented May 4, 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: 61.40% (+4.05%)

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

@tonyredondo
tonyredondo force-pushed the feat/go-ci-visibility-failnow-teardown branch from ef16981 to 12fa701 Compare May 4, 2026 14:49
@tonyredondo
tonyredondo marked this pull request as ready for review May 4, 2026 15:11
@tonyredondo
tonyredondo requested review from a team as code owners May 4, 2026 15:11
@tonyredondo
tonyredondo marked this pull request as draft May 4, 2026 15:18
@tonyredondo
tonyredondo marked this pull request as ready for review May 4, 2026 15:18
@tonyredondo
tonyredondo marked this pull request as draft May 4, 2026 15:23
@tonyredondo
tonyredondo marked this pull request as ready for review May 4, 2026 15:24
@pr-commenter

pr-commenter Bot commented May 4, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-05-05 14:48:01

Comparing candidate commit 2c6f3bb in PR branch feat/go-ci-visibility-failnow-teardown with baseline commit e2961fd in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 261 metrics, 8 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 ----------------------------------'

@kakkoyun

kakkoyun commented May 5, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

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

@codecov

codecov Bot commented May 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.07%. Comparing base (e2961fd) to head (2c6f3bb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
Files with missing lines Coverage Δ
...al/civisibility/integrations/gotesting/testingB.go 0.00% <ø> (ø)
...al/civisibility/integrations/gotesting/testingT.go 26.82% <ø> (ø)

... and 446 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.

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 51e0cfb into main May 5, 2026
194 of 196 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the feat/go-ci-visibility-failnow-teardown branch May 5, 2026 15:34
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request May 6, 2026
### What does this PR do?

Fixes several Go CI Visibility edge cases found while reviewing retry, cleanup, coverage, and Git metadata handling after #4717 and #4722.

This PR updates Go test retry orchestration so cleanup failures behave like normal test failures. A cleanup `panic` is recorded on the failing attempt, cleanup `Fatal` / `FailNow` no longer escapes the retry loop through `runtime.Goexit`, and cleanups now run after Datadog-managed parallel subtests have completed so parent cleanup order remains consistent with Go's testing lifecycle.

It also fixes Orchestrion subtest panic handling when a Datadog retry wrapper owns the execution. In that case, subtest panics are recorded as failed attempts and returned to the retry owner, instead of immediately repanicking before retries can run.

Other fixes included here:

- stop automatic flaky retries when the global retry budget reaches zero
- protect benchmark instrumentation map writes with the write lock
- synchronize coverage writer payload rotation between `add` and `flush`
- report `test.code_coverage.enabled=false` when ITR is enabled but coverage is not actually active
- avoid an index panic when Git reports a pack hash but the expected `.pack` file is missing

### Motivation

The previous CI Visibility retry fixes addressed known lifecycle bugs, but a follow-up review found more cases where retry attempts could be misclassified, skipped, or allowed to race with shared state.

The highest-risk issues were in Go cleanup and Orchestrion subtest panic flows. Both are part of the real test result, so they need to pass through the same retry owner that handles failures in the test body. Without that, a cleanup failure could be hidden or abort retry orchestration, and a retryable subtest panic could fail the process before Datadog could schedule the next attempt.

The smaller fixes remove incorrect state reporting and race-prone code paths found during the same review.

### Testing

- [x] `go test ./internal/civisibility/integrations/gotesting/failnow -count=1`
- [x] `go test ./internal/civisibility/integrations/gotesting -count=1`
- [x] `go test ./internal/civisibility/integrations/gotesting/subtests -count=1`
- [x] `go test ./internal/civisibility/utils -run 'TestCreatePackFiles|TestGit|TestPackFiles' -count=1`
- [x] `go test -race ./internal/civisibility/integrations/gotesting/coverage -count=1`
- [x] `Bypass=true go test -race ./internal/civisibility/integrations/gotesting -run TestGetFieldPointerFrom -count=1`
- [x] `PATH="$(go env GOPATH)/bin:$PATH" GOFLAGS="-timeout=30m -tags=githubci,buildtag" go run github.com/DataDog/orchestrion go test -count=1 ./parallel_testing_retries`
- [x] `git diff --check main..HEAD`

### Reviewer's Checklist
<!--
* Authors can use this list as a reference to ensure that there are no problems
  during the review but the signing off is to be done by the reviewer(s).
-->

- [ ] Changed code has unit tests for its functionality at or near 100% coverage.
- [ ] [System-Tests](https://github.com/DataDog/system-tests/) covering this feature have been added and enabled with the va.b.c-dev version tag.
- [ ] There is a benchmark for any new code, or changes to existing code.
- [ ] If this interacts with the agent in a new way, a system test has been added.
- [ ] 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.
- [ ] Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild. Make sure all nested modules are up to date by running `make fix-modules` locally.


Co-authored-by: tony.redondo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants