Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions config/_default/menus/main.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5956,6 +5956,26 @@ menu:
parent: tests_setup
identifier: tests_setup_junit_xml
weight: 108
- name: Bazel
url: tests/setup/bazel/
parent: tests_setup
identifier: tests_setup_bazel
weight: 109
- name: Java
url: tests/setup/bazel/java/
parent: tests_setup_bazel
identifier: tests_setup_bazel_java
weight: 10901
- name: Python
url: tests/setup/bazel/python/
parent: tests_setup_bazel
identifier: tests_setup_bazel_python
weight: 10902
- name: Go
url: tests/setup/bazel/go/
parent: tests_setup_bazel
identifier: tests_setup_bazel_go
weight: 10903
- name: Network Settings
url: tests/network/
parent: tests
Expand Down
3 changes: 3 additions & 0 deletions content/en/tests/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Select an option to configure Test Optimization in Datadog:

</br>

If you run Go, Java, or Python tests with Bazel, use Datadog's official [Bazel rules for Test Optimization][bazel-setup]. Bazel support is in Preview.

In addition to tests, Test Optimization provides visibility over the whole testing phase of your project.

### Supported features
Expand Down Expand Up @@ -193,3 +195,4 @@ When you're evaluating failed or flaky tests, or the performance of a CI test, y
[7]: /notebooks
[8]: https://app.datadoghq.com/ci/test-runs
[9]: /monitors/types/ci/
[bazel-setup]: /tests/setup/bazel/
3 changes: 3 additions & 0 deletions content/en/tests/setup/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ For information about configuration options for [Test Optimization][1], choose y

<br>

If you run Go, Java, or Python tests with Bazel, use Datadog's official [Bazel rules for Test Optimization][5].

If you run your tests in an environment with network restrictions,
see the [Agent Network Traffic][2] or [Agentless Network Settings][3] guide for information on how to configure whitelisting.

Expand All @@ -29,3 +31,4 @@ If you run your tests in a container, see the [Tests in Containers][4] guide for
[2]: /agent/configuration/network/
[3]: /tests/network/
[4]: /tests/containers/
[5]: /tests/setup/bazel/
80 changes: 80 additions & 0 deletions content/en/tests/setup/bazel/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
title: Configure Test Optimization with Bazel
description: Configure Test Optimization for Bazel test targets with Datadog's official Bazel rules.
further_reading:
- link: "/tests/setup/"
tag: "Documentation"
text: "Configure Test Optimization"
- link: "/tests/explorer/"
tag: "Documentation"
text: "Explore Test Results and Performance"
- link: "/tests/troubleshooting/"
tag: "Documentation"
text: "Troubleshooting Test Optimization"
---

<div class="alert alert-info">Bazel support for Test Optimization is in Preview.</div>

Datadog provides official Bazel rules for Test Optimization. Use these rules to configure Bazel test targets. The rules read Test Optimization metadata, write local payload files during test execution, and upload test results to Datadog after Bazel tests complete.

The Bazel integration keeps Datadog metadata fetches outside test execution. During module or repository resolution, Bazel fetches Test Optimization metadata from Datadog and exposes it through a generated repository. During test execution, language-specific macros pass the metadata location to the test process and configure payloads to be written under `TEST_UNDECLARED_OUTPUTS_DIR`. After tests finish, run the doctor and uploader targets with `bazel run`.

Test Impact Analysis is not supported for Bazel.

## Language setup pages

Use the language-specific setup page for your Bazel test targets:

- [Java tests][1]
- [Python tests][2]
- [Go tests][3]

## Compatibility

This section includes setup pages for the following language test targets:

| Language | Bazel macro | Notes |
|---|---|---|
| Java | `dd_topt_java_test` | Requires a `dd-java-agent` JAR label. |
| Python | `dd_topt_py_test` | Supports the managed `pytest` runner and repository-owned pytest wrappers. |
| Go | `dd_topt_go_test` | Use `test_optimization` mode for the faster standard-library `testing` path, or `general` mode for broader Orchestrion support. |

Use `datadog-rules-test-optimization` version `1.2.0` and the commit pin shown on each language setup page.

## How the Bazel flow works

The Bazel setup has four parts:

1. Add the `datadog-rules-test-optimization` module and the companion module for your language.
1. Configure a sync repository with your Datadog service name, runtime name, and runtime version.
1. Replace the language test rule with the Datadog Bazel macro for each instrumented test target.
1. Run tests, validate local payloads with the doctor target, validate enrichment with the uploader dry run, and then upload payloads.

For remote execution, configure Bazel to download test outputs locally:

```text
test:test-optimization --remote_download_outputs=all
```

Without local `test.outputs` directories, the doctor and uploader cannot inspect payload files after `bazel test`.

## Upload payloads

Run the upload flow after your Bazel tests complete. Replace `//tools/test_optimization` with the package where you declared the doctor and uploader targets:

```bash
bazel test --config=test-optimization //...
bazel run --config=test-optimization //tools/test_optimization:dd_test_optimization_doctor
bazel run --config=test-optimization //tools/test_optimization:dd_upload_payloads -- --dry-run --validate-enrichment
DD_API_KEY=<DATADOG_API_KEY> DD_SITE=<DATADOG_SITE> bazel run --config=test-optimization //tools/test_optimization:dd_upload_payloads
```

Do not pass `DD_API_KEY`, `DD_SITE`, `DD_GIT_*`, or upload endpoint variables through `--test_env`. Forward sync metadata with `--repo_env`, and pass upload credentials only to the uploader runtime.

## Further reading

{{< partial name="whats-next/whats-next.html" >}}

[1]: /tests/setup/bazel/java/
[2]: /tests/setup/bazel/python/
[3]: /tests/setup/bazel/go/
Loading
Loading