Skip to content

feat(civisibility): Bazel offline cache and payload-file modes#4503

Draft
tonyredondo wants to merge 9 commits intomainfrom
codex/rfc-bazel-topt-files-go
Draft

feat(civisibility): Bazel offline cache and payload-file modes#4503
tonyredondo wants to merge 9 commits intomainfrom
codex/rfc-bazel-topt-files-go

Conversation

@tonyredondo
Copy link
Member

Summary

This PR implements Bazel-focused offline test optimization support in dd-trace-go by adding:

  • Manifest mode (DD_TEST_OPTIMIZATION_MANIFEST_FILE) with strict v1 manifest resolution and cache-first behavior.
  • Payload-files mode (DD_TEST_OPTIMIZATION_PAYLOADS_IN_FILES) writing JSON payload envelopes to Bazel undeclared outputs (TEST_UNDECLARED_OUTPUTS_DIR).
  • Git upload / enrichment / log-forwarding skips in offline file-based modes per RFC scope.
  • New resolver/helpers in internal/civisibility/utils/test_optimization_mode.go.

Main changes

  • Added env constants and supported-config registrations for the new test optimization env vars.
  • Added mode resolver (sync.Once) with fixed manifest path and version rules.
  • Added CacheHTTPFile, MsgpackToJSON, and WritePayloadFile helpers.
  • Switched settings/known-tests/skippable/test-management endpoints to cache-first behavior in manifest mode with no HTTP fallback.
  • Made git backend endpoints no-op in manifest mode.
  • Short-circuited test-cycle and coverage transport paths in payload-files mode to write JSON files and skip HTTP sends.
  • Disabled selected git/environment tag enrichment and logs init in file/offline modes.

Tests

Added/extended tests for:

  • Mode resolution and manifest parsing.
  • Cache-first API behavior with zero HTTP hits.
  • Payload file generation and JSON shape for test-cycle and coverage payloads.
  • CI/Git/OS/runtime tag stripping in payload-files mode.

Focused validation commands run:

  • go test -count=1 ./internal/civisibility/utils/net/...
  • go test -count=1 ./internal/civisibility/integrations/...
  • go test -count=1 ./ddtrace/tracer -run 'TestCiVisibilityTransport|TestCiVisibilityTransportPayloadFilesModeWritesJSON'
  • go test -count=1 ./internal/civisibility/utils -run 'TestCurrentTestOptimizationMode|TestCacheHTTPFile|TestMsgpackToJSON'

Scope notes

  • Bazel-only scope for this iteration.
  • DDTestRunner orchestration artifacts are intentionally excluded.
  • No legacy TEST_OPTIMIZATION_* aliases and no legacy http/* cache layout are introduced.

- Add unified test optimization env vars and mode resolver with Bazel manifest lookup
- Read settings/known/skippable/test-management from cache/http in manifest mode with no network fallback
- Disable git upload paths and selected CI enrichment in offline/file modes
- Write test-cycle and coverage payloads as JSON files in payload-files mode
- Add/extend unit tests for mode resolution, cache-first APIs, payload writing, and tag stripping
@datadog-official
Copy link
Contributor

datadog-official bot commented Mar 5, 2026

⚠️ Tests

Fix all issues with BitsAI or with Cursor

⚠️ Warnings

❄️ 3 New flaky tests detected

TestEnsureSettingsInitializationManifestModeSkipsRepositoryUpload from github.com/DataDog/dd-trace-go/v2/internal/civisibility/integrations (Datadog) (Fix with Cursor)
Failed

=== RUN   TestEnsureSettingsInitializationManifestModeSkipsRepositoryUpload
==================
Write at 0x0000028fe178 by goroutine 121:
  github.com/DataDog/dd-trace-go/v2/internal/civisibility/integrations.resetCIVisibilityStateForTesting()
      /home/runner/work/dd-trace-go/dd-trace-go/internal/civisibility/integrations/testing_helpers_test.go:20 +0x78
  github.com/DataDog/dd-trace-go/v2/internal/civisibility/integrations.TestEnsureSettingsInitializationManifestModeSkipsRepositoryUpload()
      /home/runner/work/dd-trace-go/dd-trace-go/internal/civisibility/integrations/civisibility_offline_test.go:21 +0x29
  testing.tRunner()
...
TestEnsureSettingsInitializationPayloadFilesModeSkipsRepositoryUploadAndDisablesImpactedTests from github.com/DataDog/dd-trace-go/v2/internal/civisibility/integrations (Datadog) (Fix with Cursor)
Failed

=== RUN   TestEnsureSettingsInitializationPayloadFilesModeSkipsRepositoryUploadAndDisablesImpactedTests
==================
Write at 0x000002e92e88 by goroutine 88:
  github.com/DataDog/dd-trace-go/v2/internal/civisibility/integrations.resetCIVisibilityStateForTesting()
      /home/runner/work/dd-trace-go/dd-trace-go/internal/civisibility/integrations/testing_helpers_test.go:20 +0x78
  github.com/DataDog/dd-trace-go/v2/internal/civisibility/integrations.TestEnsureSettingsInitializationPayloadFilesModeSkipsRepositoryUploadAndDisablesImpactedTests()
      /home/runner/work/dd-trace-go/dd-trace-go/internal/civisibility/integrations/civisibility_offline_test.go:40 +0x29
  testing.tRunner()
...
TestPayloadFilesModeSkipsCIGitOSRuntimeTags from github.com/DataDog/dd-trace-go/v2/internal/civisibility/integrations (Datadog) (Fix with Cursor)
Failed

=== RUN   TestPayloadFilesModeSkipsCIGitOSRuntimeTags
    manual_api_mocktracer_test.go:107: 
        	Error Trace:	/home/runner/work/dd-trace-go/dd-trace-go/internal/civisibility/integrations/manual_api_mocktracer_test.go:107
        	Error:      	Should NOT be empty, but was []
        	Test:       	TestPayloadFilesModeSkipsCIGitOSRuntimeTags
--- FAIL: TestPayloadFilesModeSkipsCIGitOSRuntimeTags (0.01s)
panic: runtime error: index out of range [0] with length 0 [recovered, repanicked]

...

ℹ️ Info

🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 72.48%
Overall Coverage: 59.55% (+0.30%)

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

@pr-commenter
Copy link

pr-commenter bot commented Mar 5, 2026

Benchmarks

Benchmark execution time: 2026-03-06 19:58:35

Comparing candidate commit 63ea609 in PR branch codex/rfc-bazel-topt-files-go with baseline commit d4c51c7 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 ----------------------------------'

@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 73.39056% with 62 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.25%. Comparing base (d4c51c7) to head (63ea609).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ernal/civisibility/utils/test_optimization_mode.go 75.22% 17 Missing and 11 partials ⚠️
...civisibility/integrations/civisibility_features.go 37.93% 15 Missing and 3 partials ⚠️
internal/civisibility/utils/net/coverage.go 52.94% 5 Missing and 3 partials ⚠️
internal/civisibility/integrations/civisibility.go 64.28% 4 Missing and 1 partial ⚠️
ddtrace/tracer/civisibility_transport.go 71.42% 1 Missing and 1 partial ⚠️
internal/civisibility/utils/environmentTags.go 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
...nal/civisibility/integrations/manual_api_common.go 85.71% <100.00%> (ø)
internal/civisibility/utils/net/known_tests_api.go 81.81% <100.00%> (ø)
...ternal/civisibility/utils/net/searchcommits_api.go 79.48% <100.00%> (ø)
...ternal/civisibility/utils/net/sendpackfiles_api.go 86.20% <100.00%> (ø)
internal/civisibility/utils/net/settings_api.go 84.74% <100.00%> (ø)
internal/civisibility/utils/net/skippable.go 65.71% <100.00%> (ø)
...ivisibility/utils/net/test_management_tests_api.go 72.30% <100.00%> (ø)
internal/civisibility/utils/environmentTags.go 82.11% <75.00%> (ø)
ddtrace/tracer/civisibility_transport.go 60.91% <71.42%> (ø)
internal/civisibility/integrations/civisibility.go 61.72% <64.28%> (ø)
... and 3 more

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

- Add deterministic seams and reset helpers for offline/file mode tests
- Cover missing output-dir failures for test-cycle and coverage payload files
- Assert payload-file mode skips git enrichment and offline init skips upload/logs
- Fix malformed manifest settings cache handling discovered by the new tests
- Apply local import grouping expected by Static Checks
- Reformat the affected CI visibility test files without changing behavior

Tests: go test -count=1 ./internal/civisibility/utils/net/... && go test -count=1 ./internal/civisibility/integrations/... && go test -count=1 ./ddtrace/tracer -run 'TestCiVisibilityTransportPayloadFilesMode'
- Narrow the offline log test to a direct helper instead of re-running global CI visibility init
- Stop resetting package-wide init state in the new integration test helper
- Keep the offline/upload assertions while preserving manual_api_mocktracer test stability

Tests: INTEGRATION=true go test -shuffle=on -count=20 ./internal/civisibility/integrations && INTEGRATION=true go test -count=1 ./internal/civisibility/integrations && go test -count=1 ./internal/civisibility/utils/net/... && go test -count=1 ./ddtrace/tracer -run 'TestCiVisibilityTransportPayloadFilesMode'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant