From 276b5452f3e6dc65e06bb4ac0c722b808048b0e0 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Thu, 12 Nov 2026 20:29:25 +0100 Subject: [PATCH 1/6] Migrate microbenchmarks from benchmarking-platform into this repository Copy container/, steps/, and the regression gate config from the dd-trace-cpp branch of benchmarking-platform into .gitlab/benchmarks/. The benchmarks CI jobs call the local steps instead of cloning the platform, and the image is now built in-repo from container/ via the build-ci-images template. The image pin is a placeholder until build-benchmark-ci-images runs once on this branch. --- .gitlab-ci.yml | 1 + .gitlab/BENCHMARKS.md | 30 ------ .gitlab/benchmarks.yml | 25 +++-- .gitlab/benchmarks/README.md | 94 ++++++++++++++++ .../bp-runner.fail-on-regression.yml | 6 ++ .gitlab/benchmarks/container/Dockerfile | 4 + .../benchmarks/container/install-cpp-deps.sh | 23 ++++ .gitlab/benchmarks/steps/analyze-results.sh | 100 ++++++++++++++++++ .../steps/capture-hardware-software-info.sh | 19 ++++ .../steps/config-benchmark-analyzer.sh | 6 ++ .gitlab/benchmarks/steps/post-pr-comment.sh | 12 +++ .gitlab/benchmarks/steps/run-benchmarks.sh | 49 +++++++++ .../upload-results-to-benchmarking-api.sh | 45 ++++++++ .../benchmarks/steps/upload-results-to-s3.sh | 12 +++ 14 files changed, 390 insertions(+), 36 deletions(-) delete mode 100644 .gitlab/BENCHMARKS.md create mode 100644 .gitlab/benchmarks/README.md create mode 100644 .gitlab/benchmarks/bp-runner.fail-on-regression.yml create mode 100644 .gitlab/benchmarks/container/Dockerfile create mode 100755 .gitlab/benchmarks/container/install-cpp-deps.sh create mode 100755 .gitlab/benchmarks/steps/analyze-results.sh create mode 100755 .gitlab/benchmarks/steps/capture-hardware-software-info.sh create mode 100755 .gitlab/benchmarks/steps/config-benchmark-analyzer.sh create mode 100755 .gitlab/benchmarks/steps/post-pr-comment.sh create mode 100755 .gitlab/benchmarks/steps/run-benchmarks.sh create mode 100755 .gitlab/benchmarks/steps/upload-results-to-benchmarking-api.sh create mode 100755 .gitlab/benchmarks/steps/upload-results-to-s3.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6dda2cc18..162a2b300 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,5 @@ stages: + - ci-image - config-validation - benchmarks - benchmarks-report diff --git a/.gitlab/BENCHMARKS.md b/.gitlab/BENCHMARKS.md deleted file mode 100644 index c809df9d7..000000000 --- a/.gitlab/BENCHMARKS.md +++ /dev/null @@ -1,30 +0,0 @@ -# Benchmarks - -This describes the GitLab CI configuration for the benchmarks that run on the -[Benchmarking Platform](https://datadoghq.atlassian.net/wiki/x/egAzk). - -## Layout - -- `benchmarks.yml`: Google Benchmark microbenchmarks. - - `benchmarks` clones `benchmarking-platform` (`dd-trace-cpp` branch), runs the benchmark, - converts and analyzes results, uploads and comments on the PR. - - `check-big-regressions` fails on regressions above the threshold defined on - `bp-runner.fail-on-regression.yml` in the `dd-trace-cpp` branch of - [benchmarking-platform](https://github.com/DataDog/benchmarking-platform). - -## Marking a Benchmark as Flaky - -Add it to `FLAKY_BENCHMARKS_REGEX` in the `benchmarks` job's `variables` in `benchmarks.yml`. - -The benchmark still runs and reports, but doesn't 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. diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index 14250c46d..ea4049067 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -1,5 +1,21 @@ +# 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' + variables: - BENCHMARKS_CI_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:dd-trace-cpp + # Consumed by the benchmark jobs below. Repin after a `build-benchmark-ci-images` + # run to the tag it pushes. + # Placeholder pin: `build-benchmark-ci-images` has not run on this branch yet. + # Run it once, then replace this tag with the produced one. + BENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-cpp-PLACEHOLDER + + # Consumed by the included build-ci-images template. 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 benchmarks: stage: benchmarks @@ -14,8 +30,7 @@ benchmarks: 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" + - export PATH="$PATH:${CI_PROJECT_DIR}/.gitlab/benchmarks/steps" - capture-hardware-software-info.sh - run-benchmarks.sh - analyze-results.sh @@ -55,7 +70,5 @@ check-big-regressions: 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 + bp-runner "$CI_PROJECT_DIR/.gitlab/benchmarks/bp-runner.fail-on-regression.yml" --debug diff --git a/.gitlab/benchmarks/README.md b/.gitlab/benchmarks/README.md new file mode 100644 index 000000000..8017cb581 --- /dev/null +++ b/.gitlab/benchmarks/README.md @@ -0,0 +1,94 @@ +# 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: + +- **`steps/`** — the run, analyze, upload, and PR-comment scripts called by the + `benchmarks` CI job in [`../benchmarks.yml`](../benchmarks.yml). +- **`container/`** — Dockerfile and install script for the benchmarks CI image. +- **`bp-runner.fail-on-regression.yml`** — gate config. The + `check-big-regressions` job runs it with `bp-runner` and fails the pipeline on + regressions above `regression_threshold`. + +Execution flow on each PR: + +1. The `benchmarks` job collects hardware info, runs `benchmark/` twice + (candidate and baseline), converts and analyzes the results, uploads them to + S3 and the BP API, and comments on the PR. +2. 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/` or the scripts in `steps/`. No image rebuild is +needed for those: the image only carries the toolchain, not the benchmarks. +Rebuild the image (see below) only when `container/` 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 CI steps, mimic the `benchmarks` job script: set +`ARTIFACTS_DIR`, `UPSTREAM_PROJECT_NAME`, `UPSTREAM_BRANCH`, and +`UPSTREAM_COMMIT_SHA`, put this directory's `steps/` on `PATH`, then call the +scripts in the same order as the job. Some scripts 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-`. +3. Copy the produced tag and the job URL, and pin + `BENCHMARKS_CI_IMAGE` in [`../benchmarks.yml`](../benchmarks.yml) to it: + +```yaml +# Image built here: +BENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-cpp- +``` + +4. Push the update and verify a green pipeline before merging. diff --git a/.gitlab/benchmarks/bp-runner.fail-on-regression.yml b/.gitlab/benchmarks/bp-runner.fail-on-regression.yml new file mode 100644 index 000000000..d6be11d7e --- /dev/null +++ b/.gitlab/benchmarks/bp-runner.fail-on-regression.yml @@ -0,0 +1,6 @@ +experiments: + - name: Run regression check + steps: + - name: Fail on regression + run: fail_on_regression + regression_threshold: 5.0 # percents diff --git a/.gitlab/benchmarks/container/Dockerfile b/.gitlab/benchmarks/container/Dockerfile new file mode 100644 index 000000000..f6ab5f837 --- /dev/null +++ b/.gitlab/benchmarks/container/Dockerfile @@ -0,0 +1,4 @@ +FROM registry.ddbuild.io/images/benchmarking-platform-tools-ubuntu:latest + +COPY install-cpp-deps.sh ./install-cpp-deps.sh +RUN ./install-cpp-deps.sh diff --git a/.gitlab/benchmarks/container/install-cpp-deps.sh b/.gitlab/benchmarks/container/install-cpp-deps.sh new file mode 100755 index 000000000..fa9f218f8 --- /dev/null +++ b/.gitlab/benchmarks/container/install-cpp-deps.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -e + +apt-get update && apt-get install --yes software-properties-common && \ + add-apt-repository ppa:git-core/ppa --yes && \ + apt-get update && apt-get upgrade --yes && \ + apt-get install --yes \ + wget build-essential clang sed gdb clang-format git ssh shellcheck \ + libc++-dev libc++abi-dev + +git clone --branch main https://github.com/DataDog/dd-trace-cpp/ /dd-trace-cpp/ && cd /dd-trace-cpp/ +cp bin/install-cmake /tmp/install-cmake +chmod +x /tmp/install-cmake && /tmp/install-cmake && rm /tmp/install-cmake +cd / && rm -rf /dd-trace-cpp + +git clone https://github.com/google/benchmark.git +cd benchmark +cmake -E make_directory "build" +cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../ +cmake --build "build" --config Release +cmake -E chdir "build" ctest --build-config Release +cmake --build "build" --config Release --target install diff --git a/.gitlab/benchmarks/steps/analyze-results.sh b/.gitlab/benchmarks/steps/analyze-results.sh new file mode 100755 index 000000000..db03f1d58 --- /dev/null +++ b/.gitlab/benchmarks/steps/analyze-results.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash + +set -ex + +# Benchmark analyzer config + +source "$(dirname "$0")/config-benchmark-analyzer.sh" + +CPU_MODEL=$(cat "$ARTIFACTS_DIR/lscpu.txt" | grep -Eo 'Model name: .*' | sed 's/Model name://' | awk '{$1=$1;print}') +CI_JOB_DATE=$(date +%s) + +if [ -z "$CPU_MODEL" ]; then + echo "FAIL! Failed to extract CPU_MODEL from lscpu.txt" + exit 1 +fi + +KERNEL_VERSION=$(uname -a || echo "Unknown") + +# -- Analyze candidate branch results + +CANDIDATE_BRANCH=$UPSTREAM_BRANCH +CANDIDATE_SRC="/app/candidate/" +CANDIDATE_RESULTS="$ARTIFACTS_DIR/candidate.json" + +# Get commit SHA for candidate branch +cd "$CANDIDATE_SRC/" +CANDIDATE_COMMIT_SHA=$(git rev-parse HEAD) +CANDIDATE_COMMIT_DATE=$(git show -s --format=%ct $CANDIDATE_COMMIT_SHA) + +benchmark_analyzer convert \ + --extra-params="{\ + \"config\":\"candidate\", \ + \"baseline_or_candidate\":\"candidate\", \ + \"kernel_version\":\"$KERNEL_VERSION\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$CANDIDATE_COMMIT_SHA\", \ + \"git_commit_date\":\"$CANDIDATE_COMMIT_DATE\", \ + \"git_branch\":\"$CANDIDATE_BRANCH\"\ + }" \ + --framework=GoogleBenchmark \ + --outpath="$ARTIFACTS_DIR/candidate.converted.json" \ + "$CANDIDATE_RESULTS" + +benchmark_analyzer analyze \ + --format=md \ + --outpath="$ARTIFACTS_DIR/candidate-analysis.md" \ + "$ARTIFACTS_DIR/candidate.converted.json" + + +# -- Analyze baseline branch results + +BASELINE_SRC="/app/baseline/" +if [ -d $BASELINE_SRC ]; then + BASELINE_BRANCH=$(github-find-merge-into-branch --for-repo="$UPSTREAM_PROJECT_NAME" --for-pr="$UPSTREAM_BRANCH" || :) + BASELINE_RESULTS="$ARTIFACTS_DIR/baseline.json" + + # Get commit SHA for baseline branch + cd "$BASELINE_SRC/" + BASELINE_COMMIT_SHA=$(git rev-parse HEAD) + BASELINE_COMMIT_DATE=$(git show -s --format=%ct $BASELINE_COMMIT_SHA) + + benchmark_analyzer convert \ + --extra-params="{\ + \"config\":\"baseline\", \ + \"baseline_or_candidate\":\"baseline\", \ + \"kernel_version\":\"$KERNEL_VERSION\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$BASELINE_COMMIT_SHA\", \ + \"git_commit_date\":\"$BASELINE_COMMIT_DATE\", \ + \"git_branch\":\"$BASELINE_BRANCH\"\ + }" \ + --framework=GoogleBenchmark \ + --outpath="$ARTIFACTS_DIR/baseline.converted.json" \ + "$BASELINE_RESULTS" + + benchmark_analyzer analyze \ + --format=md \ + --outpath="$ARTIFACTS_DIR/baseline-analysis.md" \ + "$ARTIFACTS_DIR/baseline.converted.json" + + echo "$BASELINE_BRANCH" > "$ARTIFACTS_DIR/baseline_branch.txt" +fi + + +# -- Compare results between baseline and candidate branches + +if [ -d $BASELINE_SRC ]; then + benchmark_analyzer compare pairwise \ + --baseline='{"config":"baseline"}' \ + --candidate='{"config":"candidate"}' \ + --format=md-nodejs \ + --outpath="$ARTIFACTS_DIR/comparison-baseline-vs-candidate.md" \ + "$ARTIFACTS_DIR/baseline.converted.json" "$ARTIFACTS_DIR/candidate.converted.json" +fi diff --git a/.gitlab/benchmarks/steps/capture-hardware-software-info.sh b/.gitlab/benchmarks/steps/capture-hardware-software-info.sh new file mode 100755 index 000000000..bd841356a --- /dev/null +++ b/.gitlab/benchmarks/steps/capture-hardware-software-info.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +cd "${ARTIFACTS_DIR}" + +# Collect software information + +(which top && top -b -n 1 > top.txt) || : +(which uname && uname -a > uname.txt) || : +(which ldconfig && ldconfig -v > ldconfig.txt) || : +(which sysctl && sysctl -a > sysctl.txt) || : + +# Collect hardware information + +(which lscpu && lscpu -e > lscpu-e.txt) || : +(which lscpu && lscpu > lscpu.txt) || : +(which hwinfo && hwinfo --short > hwinfo-short.txt) || : +(which hwinfo && hwinfo > hwinfo-full.txt) || : +(which cpupower && cpupower frequency-info > cpupower-frequency-info.txt) || : +(which turbostat && turbostat -n 1 > turbostat.txt) || : diff --git a/.gitlab/benchmarks/steps/config-benchmark-analyzer.sh b/.gitlab/benchmarks/steps/config-benchmark-analyzer.sh new file mode 100755 index 000000000..0d3a3a7e2 --- /dev/null +++ b/.gitlab/benchmarks/steps/config-benchmark-analyzer.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +export UNCONFIDENCE_THRESHOLD=2.0 +export DISABLE_NHST=1 +export CI_TYPE=theoretical +export MD_REPORT_ONLY_CHANGES=1 diff --git a/.gitlab/benchmarks/steps/post-pr-comment.sh b/.gitlab/benchmarks/steps/post-pr-comment.sh new file mode 100755 index 000000000..4e1212caf --- /dev/null +++ b/.gitlab/benchmarks/steps/post-pr-comment.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Temporarily enable uploading from inside pr commenter script, till dd-trace-cpp repo has an update +"$(dirname "$0")/upload-results-to-benchmarking-api.sh" || : + +# Post comparison with baseline when running on a PR +BASELINE_BRANCH=$(github-find-merge-into-branch --for-repo="$UPSTREAM_PROJECT_NAME" --for-pr="$UPSTREAM_BRANCH") +if [ -n "$BASELINE_BRANCH" ]; then + cat "$ARTIFACTS_DIR/comparison-baseline-vs-candidate.md" | pr-commenter --for-repo="$UPSTREAM_PROJECT_NAME" --for-pr="$UPSTREAM_BRANCH" --header="Benchmarks" --on-duplicate=replace +fi diff --git a/.gitlab/benchmarks/steps/run-benchmarks.sh b/.gitlab/benchmarks/steps/run-benchmarks.sh new file mode 100755 index 000000000..be51cf626 --- /dev/null +++ b/.gitlab/benchmarks/steps/run-benchmarks.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +set -ex + +# More repetitions --> better representativeness of measurements --> less false negatives and false positives. +# However, the larger is repetitions count - the more time it will take to run benchmarks. So this is a tradeoff +# between rate of false positives / false negatives and time spent on running benchmarks. +# +# Must be at least REPETITIONS_COUNT=3 for confidence intervals calculation to work at all. +REPETITIONS_COUNT=10 + +# -- Candidate release + +CANDIDATE_SRC="/app/candidate/" +CANDIDATE_BRANCH=$UPSTREAM_BRANCH +CANDIDATE_COMMIT_SHA=$UPSTREAM_COMMIT_SHA + +# Clone your candidate release +git clone --recurse-submodules --branch $CANDIDATE_BRANCH https://github.com/DataDog/dd-trace-cpp/ "$CANDIDATE_SRC" && \ + cd "$CANDIDATE_SRC" && \ + git checkout $CANDIDATE_COMMIT_SHA + +# Run benchmarks for candidate release +cd "$CANDIDATE_SRC" +bin/benchmark --benchmark_repetitions=$REPETITIONS_COUNT --benchmark_format=json --benchmark_out="$ARTIFACTS_DIR/candidate.json" + +# -- Baseline release + +if [ -z "$BASELINE_COMMIT_SHA" ]; then + BASELINE_BRANCH=$(github-find-merge-into-branch --for-repo="$UPSTREAM_PROJECT_NAME" --for-pr="$UPSTREAM_BRANCH" || :) + + if [ ! -z "$BASELINE_BRANCH" ]; then + cd "$CANDIDATE_SRC" + BASELINE_COMMIT_SHA=$(git merge-base origin/$BASELINE_BRANCH origin/$CANDIDATE_BRANCH) + fi +fi + +if [ ! -z "$BASELINE_COMMIT_SHA" ]; then + BASELINE_SRC="/app/baseline/" + + # Clone your baseline release + git clone --recurse-submodules --branch $BASELINE_BRANCH https://github.com/DataDog/dd-trace-cpp/ "$BASELINE_SRC" && \ + cd "$BASELINE_SRC" && \ + git checkout $BASELINE_COMMIT_SHA + + # Run benchmarks for baseline release + cd "$BASELINE_SRC" + bin/benchmark --benchmark_repetitions=$REPETITIONS_COUNT --benchmark_format=json --benchmark_out="$ARTIFACTS_DIR/baseline.json" +fi diff --git a/.gitlab/benchmarks/steps/upload-results-to-benchmarking-api.sh b/.gitlab/benchmarks/steps/upload-results-to-benchmarking-api.sh new file mode 100755 index 000000000..a16003657 --- /dev/null +++ b/.gitlab/benchmarks/steps/upload-results-to-benchmarking-api.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +source "$(dirname "$0")/config-benchmark-analyzer.sh" + +PROJECT=dd-trace-cpp + +function upload_results_to_api() { + set -e + + PREFIX=$1 + BASELINE_PREFIX=$2 + CONVERTED_JSON="$PREFIX.converted.json" + + if [ ! -f "$CONVERTED_JSON" ]; then + echo "FAIL! ${CONVERTED_JSON} was not found, uploading failed!" + return + fi + + if [ -f "${BASELINE_PREFIX}.converted.json" ]; then + BASELINE_COMMIT_SHA=$(cat "${BASELINE_PREFIX}.converted.json" | jq -c '.benchmarks[0].parameters.git_commit_sha' | tr -d '''"' ) + BASELINE_CI_PIPELINE_ID=$(cat "${BASELINE_PREFIX}.converted.json" | jq -c '.benchmarks[0].parameters.ci_pipeline_id' | tr -d '''"' ) + fi + + STATUSCODE=$(curl -s --output /dev/stderr --write-out "%{http_code}" --form file=@"$CONVERTED_JSON" "https://benchmarking-service.us1.prod.dog/benchmarks/upload/$PROJECT?baseline_commit_sha=$BASELINE_COMMIT_SHA&baseline_ci_pipeline_id=$BASELINE_CI_PIPELINE_ID") + if test $STATUSCODE -ne 200; then + exit 1 + fi + + echo "SUCCESS! Uploaded $CONVERTED_JSON to Benchmarking Platform service!" +} + +cd "$ARTIFACTS_DIR" +for fcandidate in candidate.converted.json; do + [ -e "$fcandidate" ] || continue + + fcandidate=$(echo "$fcandidate" | sed "s#$ARTIFACTS_DIR/##g" | sed "s#\\.converted\\.json##g") + fbaseline=$(echo "$fcandidate" | sed "s#candidate#baseline#g") + + if [[ -f "$fbaseline.converted.json" ]]; then + upload_results_to_api $fbaseline "" + upload_results_to_api $fcandidate $fbaseline + else + upload_results_to_api $fcandidate "" + fi +done diff --git a/.gitlab/benchmarks/steps/upload-results-to-s3.sh b/.gitlab/benchmarks/steps/upload-results-to-s3.sh new file mode 100755 index 000000000..f5e0a37dd --- /dev/null +++ b/.gitlab/benchmarks/steps/upload-results-to-s3.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +PROJECT="${UPSTREAM_PROJECT_NAME:-$CI_PROJECT_NAME}" +BRANCH="${UPSTREAM_BRANCH:-$CI_COMMIT_REF_NAME}" + +# BP_EXTERNAL_S3_URL overrides the default destination prefix (must stay within +# relenv-benchmarking-data) so an external orchestrator can collect results +# under a prefix it controls. +S3_URL="${BP_EXTERNAL_S3_URL:-s3://relenv-benchmarking-data/${PROJECT}/${BRANCH}/${CI_JOB_ID}/}" +[[ "$S3_URL" == s3://relenv-benchmarking-data/* ]] || { echo "BP_EXTERNAL_S3_URL must stay within relenv-benchmarking-data" >&2; exit 1; } + +aws s3 cp --recursive --acl bucket-owner-full-control "${ARTIFACTS_DIR}/" "$S3_URL" From e087ac9786a69fd67301baa6f49717b42660ab7a Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Thu, 12 Nov 2026 20:41:33 +0100 Subject: [PATCH 2/6] Pin in-repo-built benchmarks image --- .gitlab/benchmarks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index ea4049067..3bb61a25f 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -10,7 +10,7 @@ variables: # run to the tag it pushes. # Placeholder pin: `build-benchmark-ci-images` has not run on this branch yet. # Run it once, then replace this tag with the produced one. - BENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-cpp-PLACEHOLDER + BENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-cpp-152738462 # Consumed by the included build-ci-images template. The per-pipeline # suffix gives each build a unique tag. From 7182b3cd29760f16730276da87d76c374588488d Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Thu, 12 Nov 2026 21:00:25 +0100 Subject: [PATCH 3/6] Document the image repin procedure above the pin --- .gitlab/benchmarks.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index 3bb61a25f..81b08defa 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -6,10 +6,9 @@ include: file: 'images/templates/gitlab/build-ci-images.template.yml' variables: - # Consumed by the benchmark jobs below. Repin after a `build-benchmark-ci-images` - # run to the tag it pushes. - # Placeholder pin: `build-benchmark-ci-images` has not run on this branch yet. - # Run it once, then replace this tag with the produced one. + # 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-). BENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-cpp-152738462 # Consumed by the included build-ci-images template. The per-pipeline From c64374e78a7f6aebd6f57abc5db83757a2550f4d Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Fri, 13 Nov 2026 11:19:47 +0100 Subject: [PATCH 4/6] Run the image build job in the benchmarks stage --- .gitlab-ci.yml | 1 - .gitlab/benchmarks.yml | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 162a2b300..6dda2cc18 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,4 @@ stages: - - ci-image - config-validation - benchmarks - benchmarks-report diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index 81b08defa..c2dc1ca49 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -16,6 +16,11 @@ variables: 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: stage: benchmarks when: on_success From 144f0aaedaf285bac0c26e2cd1109ec6ab9159f4 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Fri, 13 Nov 2026 11:28:03 +0100 Subject: [PATCH 5/6] Repin benchmarks image to the 152753089 build --- .gitlab/benchmarks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index c2dc1ca49..652c0f66e 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -9,7 +9,7 @@ variables: # 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-). - BENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-cpp-152738462 + BENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-cpp-152753089 # Consumed by the included build-ci-images template. The per-pipeline # suffix gives each build a unique tag. From 1e2f66eee0063b09211f2bcc186a1de9d789a769 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Fri, 13 Nov 2026 11:33:20 +0100 Subject: [PATCH 6/6] Repin benchmarks image to the 152931925 build --- .gitlab/benchmarks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index 652c0f66e..819a74b81 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -9,7 +9,7 @@ variables: # 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-). - BENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-cpp-152753089 + BENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-cpp-152931925 # Consumed by the included build-ci-images template. The per-pipeline # suffix gives each build a unique tag.