Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
e5d93fc
Migrate microbenchmarks from benchmarking-platform into this repository
igoragoli Nov 17, 2026
15893af
ci(benchmarks): drop the analyzer-settings comment from the bp-runner…
igoragoli Nov 17, 2026
dc402a6
docs(benchmarks): call the bp-runner files configurations, not experi…
igoragoli Nov 17, 2026
c66b881
Merge remote-tracking branch 'origin/main' into augusto/cpp-microbenc…
igoragoli Nov 17, 2026
3eb3a68
ci(benchmarks): retry S3 upload on failure
igoragoli Nov 17, 2026
178d65e
docs(benchmarks): tighten comments
igoragoli Nov 17, 2026
09faaa0
ci(benchmarks): slim down the CI image dependencies
igoragoli Nov 26, 2026
aff7db7
ci(benchmarks): simplify the release fetch in bp-runner.yml
igoragoli Nov 26, 2026
a8ba50d
ci(benchmarks): factorize analyzer settings, rules, and artifacts
igoragoli Nov 26, 2026
f278f41
docs(benchmarks): sort the file list and capitalize section titles
igoragoli Nov 26, 2026
f023a99
ci(benchmarks): repin the image to the slimmed-down build 156635051
igoragoli Nov 26, 2026
928bed4
ci(benchmarks): tidy comments in benchmarks.yml
igoragoli Nov 27, 2026
2c2805d
ci(benchmarks): share the bp-runner prelude across jobs
igoragoli Nov 27, 2026
1fdc474
ci(benchmarks): simplify install-cpp-deps.sh
igoragoli Nov 27, 2026
9ae512d
ci(benchmarks): stop the release fetch on the first error
igoragoli Nov 27, 2026
4b279da
docs(benchmarks): trim the README file list and the image repin step
igoragoli Nov 27, 2026
5119c0a
docs(benchmarks): name the job and config instead of "experiment"
igoragoli Nov 27, 2026
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
30 changes: 0 additions & 30 deletions .gitlab/BENCHMARKS.md

This file was deleted.

108 changes: 74 additions & 34 deletions .gitlab/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,101 @@
# The benchmarks CI image is built in-repo from .gitlab/benchmarks/container/
# by the `build-benchmark-ci-images` job of the shared template.
# @see https://github.com/DataDog/benchmarking-platform-tools/blob/main/images/templates/gitlab/build-ci-images.template.yml
include:
- project: 'DataDog/benchmarking-platform-tools'
file: 'images/templates/gitlab/build-ci-images.template.yml'

.analyzer-settings: &analyzer-settings
UNCONFIDENCE_THRESHOLD: "2.0"
DISABLE_NHST: "1"
CI_TYPE: "theoretical"
MD_REPORT_ONLY_CHANGES: "1"

.benchmarks-rules: &benchmarks-rules
- if: $CI_COMMIT_BRANCH == "main"
interruptible: false
- interruptible: true

.reports-artifacts: &reports-artifacts
name: "reports"
when: always
paths:
- reports/
expire_in: 3 months

# bp-runner writes reports to ARTIFACTS_DIR. The insteadOf rule makes clones
# of github.com/DataDog go through gitlab.ddbuild.io.
.bp-runner-prelude:
before_script:
- export ARTIFACTS_DIR="$(pwd)/reports" && (mkdir "${ARTIFACTS_DIR}" || :)
- git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/".insteadOf "https://github.com/DataDog/"

variables:
BENCHMARKS_CI_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:dd-trace-cpp
# Consumed by the benchmark jobs below. To rebuild the image, run the manual
# `build-benchmark-ci-images` job and repin to the tag it pushes
# (dd-trace-cpp-<pipeline id>).
BENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-cpp-156635051

# The per-pipeline suffix gives each build a unique tag.
BASE_CI_IMAGE_SUFFIX: dd-trace-cpp-${CI_PIPELINE_ID}
BASE_CI_IMAGE_CONTAINER_DIR: .gitlab/benchmarks/container

# The template puts this job in the ci-image stage; run it next to the
# benchmarks it builds for instead.
build-benchmark-ci-images:
stage: benchmarks

benchmarks:
extends: .bp-runner-prelude
stage: benchmarks
when: on_success
tags: ["runner:apm-k8s-tweaked-metal"]
image: $BENCHMARKS_CI_IMAGE
rules:
- if: $CI_COMMIT_BRANCH == "main"
interruptible: false
- interruptible: true
rules: *benchmarks-rules
timeout: 15m
script:
- export ARTIFACTS_DIR="$(pwd)/reports" && (mkdir "${ARTIFACTS_DIR}" || :)
- git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/".insteadOf "https://github.com/DataDog/"
- git clone --branch dd-trace-cpp https://github.com/DataDog/benchmarking-platform /platform
- export PATH="$PATH:/platform/steps"
- capture-hardware-software-info.sh
- run-benchmarks.sh
- analyze-results.sh
- "upload-results-to-s3.sh || :"
- "post-pr-comment.sh || :"
artifacts:
name: "reports"
when: always
paths:
- reports/
expire_in: 3 months
- bp-runner .gitlab/benchmarks/bp-runner.yml --debug
artifacts: *reports-artifacts
variables:
UPSTREAM_PROJECT_ID: $CI_PROJECT_ID # The ID of the current project. This ID is unique across all projects on the GitLab instance.
UPSTREAM_PROJECT_NAME: $CI_PROJECT_NAME # "dd-trace-cpp"
UPSTREAM_BRANCH: $CI_COMMIT_REF_NAME # The branch or tag name for which project is built.
UPSTREAM_COMMIT_SHA: $CI_COMMIT_SHA # The commit revision the project is built for.
# See https://datadoghq.atlassian.net/wiki/x/dAKLrgE for more details.
FLAKY_BENCHMARKS_REGEX: ""
<<: *analyzer-settings

# Posts the comparison and uploads results. allow_failure keeps a failure here
# from failing the pipeline, and a separate job avoids the parallel-teardown
# race with the S3 upload.
benchmarks-pr-comment:
extends: .bp-runner-prelude
stage: benchmarks-report
needs: [ benchmarks ]
allow_failure: true
when: on_success
tags: ["arch:amd64"]
image: $BENCHMARKS_CI_IMAGE
timeout: 30m
rules: *benchmarks-rules
variables:
# Analyzer settings the PR comment's comparison output depends on.
<<: *analyzer-settings
script:
- bp-runner .gitlab/benchmarks/bp-runner.pr-comment.yml --debug
artifacts: *reports-artifacts

# This repository is using PR-level performance quality gates.
# Verify that the check-big-regressions CI job has passed. If any regression happened, merging this PR will be blocked.

# If bypassing is necessary, see https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/5158175217/Performance+quality+gates+-+User+Guide for more details.
check-big-regressions:
extends: .bp-runner-prelude
stage: benchmarks-report
needs: [ benchmarks ]
when: on_success
rules:
- if: $CI_COMMIT_BRANCH == "main"
interruptible: false
- interruptible: true
rules: *benchmarks-rules
tags: ["arch:amd64"]
image: $BENCHMARKS_CI_IMAGE
script: |
export ARTIFACTS_DIR="$(pwd)/reports/"
if [[ -n "$CI_JOB_TOKEN" ]];
then
git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/".insteadOf "https://github.com/DataDog/"
fi
git clone --branch dd-trace-cpp https://github.com/DataDog/benchmarking-platform /platform
export PATH="$PATH:/platform/steps"

bp-runner /platform/bp-runner.fail-on-regression.yml --debug
script:
- bp-runner .gitlab/benchmarks/bp-runner.fail-on-regression.yml --debug
100 changes: 100 additions & 0 deletions .gitlab/benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Microbenchmarks

The pipeline runs [Google Benchmark](https://github.com/google/benchmark)
microbenchmarks from `benchmark/` on the Benchmarking Platform, and compares them
against a baseline to detect regressions on every PR.

Files in this directory:

- **`bp-runner.fail-on-regression.yml`**: `bp-runner` config for the regression
gate.
- **`bp-runner.pr-comment.yml`**: `bp-runner` config for the PR comment.
- **`bp-runner.yml`**: `bp-runner` config for the benchmark run.
- **`container/`**: Dockerfile and install script for the benchmarks CI image.

Execution flow on each PR:

1. The `benchmarks` job runs `bp-runner .gitlab/benchmarks/bp-runner.yml
--debug`: it collects hardware info, runs `benchmark/` twice (candidate and
baseline), converts and analyzes the results, and uploads them to S3.
2. The `benchmarks-pr-comment` job runs
`bp-runner .gitlab/benchmarks/bp-runner.pr-comment.yml --debug`, posts
the comparison on the PR, and uploads the results to the BP API.
3. The `check-big-regressions` job runs
`bp-runner.fail-on-regression.yml` and fails on regressions above the
threshold.

## How to Add a Benchmark

1. Write it in [`benchmark/`](../../benchmark/) using Google Benchmark, and add
the source file to `benchmark/CMakeLists.txt`.
2. Verify it runs locally (see below).

New benchmarks that don't exist on the baseline branch are skipped from the
baseline comparison on the first run.

## How to Update a Benchmark

Edit the source in `benchmark/`. The `benchmarks` job only builds and runs what
is in `benchmark/`, so no config change is needed to add, edit, or remove a
benchmark. Edit `bp-runner.yml` when the flow itself changes (fetch, run,
analyze, upload), and `container/` only when the toolchain changes.

## How to Mark a Benchmark as Flaky

Add it to `FLAKY_BENCHMARKS_REGEX` in the `benchmarks` job's `variables` in
[`../benchmarks.yml`](../benchmarks.yml). The benchmark still runs and reports,
but it does not fail the gate.

- The regex matches anywhere in the scenario name.
- `BM_Trace` quarantines every scenario containing it, like
`BM_TraceTinyCCSource`.
- Anchor with `^...$` to target one scenario.

```yaml
FLAKY_BENCHMARKS_REGEX: "^BM_TraceTinyCCSource$"
```

Open a ticket to fix or remove it. See
[Flaky Benchmarks Monitoring](https://datadoghq.atlassian.net/wiki/x/dAKLrgE)
for more details.

## How to Run a Benchmark Locally

From the repository root:

```bash
bin/benchmark --benchmark_repetitions=10 --benchmark_format=json --benchmark_out=candidate.json
```

`bin/benchmark` builds `dd-trace-cpp` and the benchmark, then runs it.

To run the full `bp-runner.yml` flow locally, install `bp-runner` and run it
against the config, like the job does:

```bash
export ARTIFACTS_DIR="$(pwd)/reports"
bp-runner .gitlab/benchmarks/bp-runner.yml --debug
```

Some steps need tools that only exist in the CI image (`benchmark_analyzer`,
`github-find-merge-into-branch`, `pr-commenter`).

## How to Rebuild the CI Image

The `BENCHMARKS_CI_IMAGE` used by the benchmark jobs is built from
`container/`. Rebuild and repin it whenever `container/` changes.

1. Edit the files under `container/`. Push the branch.
2. On the pipeline, run the manual `build-benchmark-ci-images` job. It is
defined by
[`build-ci-images.template.yml`](https://github.com/DataDog/benchmarking-platform-tools/blob/main/images/templates/gitlab/build-ci-images.template.yml)
and pushes `registry.ddbuild.io/ci/benchmarking-platform:dd-trace-cpp-<pipeline id>`.
3. Copy the produced tag, and pin `BENCHMARKS_CI_IMAGE` in
[`../benchmarks.yml`](../benchmarks.yml) to it:

```yaml
BENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-cpp-<pipeline id>
```

4. Push the update and verify a green pipeline before merging.
6 changes: 6 additions & 0 deletions .gitlab/benchmarks/bp-runner.fail-on-regression.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
experiments:
- name: Run regression check
steps:
- name: Fail on regression
run: fail_on_regression
regression_threshold: 5.0 # percents
10 changes: 10 additions & 0 deletions .gitlab/benchmarks/bp-runner.pr-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
experiments:
- name: Post PR comment
steps:
- name: Post PR comment
run: post_pr_comment

global_teardown:
- name: Upload to BP API
run: upload_to_bp_api
project: dd-trace-cpp
34 changes: 34 additions & 0 deletions .gitlab/benchmarks/bp-runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
global_setup:
- name: Capture hardware/software info
run: collect_hardware_software_info

experiments:
- name: Microbenchmarks
steps:
- name: Run benchmarks
run: run_microbenchmarks
repo: DataDog/dd-trace-cpp
# The default fetch does not initialise submodules, and the benchmark
# binary needs the google-benchmark and tinycc submodules.
how_to_fetch_release: |
set -e
git clone --branch "$BRANCH" https://github.com/DataDog/dd-trace-cpp/ "$CODE_SRC"
Comment thread
igoragoli marked this conversation as resolved.
Resolved
cd "$CODE_SRC" && git checkout "$COMMIT_SHA"
git submodule update --init --recursive
# --benchmark_out makes the analyzer find the results file, named
# the way the fail-on-regression gate already globs.
how_to_run_benchmarks: |
bin/benchmark --benchmark_repetitions=10 --benchmark_format=json --benchmark_out="$ARTIFACTS_DIR/$BASELINE_OR_CANDIDATE.json"

- name: Analyze results
run: analyze_microbenchmarks
framework: GoogleBenchmark

global_teardown:
- name: Upload to S3
run: upload_to_s3
Comment thread
igoragoli marked this conversation as resolved.
Resolved
# S3 upload failures are usually transient and the upload is idempotent,
# so retry twice before failing the job (3 attempts total).
retries_on_failure: 2
Comment thread
igoragoli marked this conversation as resolved.
Resolved
# If BP_EXTERNAL_S3_URL is empty, bp-runner uses its default S3 destination.
url: $BP_EXTERNAL_S3_URL
4 changes: 4 additions & 0 deletions .gitlab/benchmarks/container/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM registry.ddbuild.io/images/benchmarking-platform-tools-ubuntu:latest

COPY install-cpp-deps.sh .
RUN ./install-cpp-deps.sh
9 changes: 9 additions & 0 deletions .gitlab/benchmarks/container/install-cpp-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e

apt-get update && apt-get install --yes build-essential git sed wget

git clone --depth 1 --branch main https://github.com/DataDog/dd-trace-cpp/ /dd-trace-cpp/
/dd-trace-cpp/bin/install-cmake
rm -rf /dd-trace-cpp