From 2db31d20eb6f4a0003f75cd925ff4b4a69ae54b8 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Tue, 17 Nov 2026 11:32:55 +0100 Subject: [PATCH 01/14] ci(benchmarks): migrate microbenchmarks into the repo and run them on bp-runner Move the suite in-repo (container and configs from the BP dd-trace-php branch), build the CI image via the shared build-ci-images template, and run the three micro jobs on bp-runner configs: datadog_agent with the in-repo config script, one-time setup, run with the output layout and CPU pinning preserved, per-framework analysis (PHPBench, GoogleBenchmark for tea, Sirun for profiler), S3 and BP API uploads, and a separate allow-failure PR-comment job. --- .claude/ci/benchmarks.md | 15 +- .gitlab/BENCHMARKS.md | 60 ------ .gitlab/benchmarks.yml | 99 +++++++-- .gitlab/benchmarks/README.md | 190 ++++++++++++++++++ .../bp-runner.fail-on-regression.yml | 6 + .gitlab/benchmarks/bp-runner.pr-comment.yml | 10 + .gitlab/benchmarks/bp-runner.yml | 150 ++++++++++++++ .gitlab/benchmarks/container/Dockerfile | 117 +++++++++++ .../steps/update-dd-agent-config.sh | 25 +++ .gitlab/generate-package.php | 1 + 10 files changed, 587 insertions(+), 86 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/bp-runner.pr-comment.yml create mode 100644 .gitlab/benchmarks/bp-runner.yml create mode 100644 .gitlab/benchmarks/container/Dockerfile create mode 100755 .gitlab/benchmarks/steps/update-dd-agent-config.sh diff --git a/.claude/ci/benchmarks.md b/.claude/ci/benchmarks.md index 0670f0a7208..cc7eaf05a6c 100644 --- a/.claude/ci/benchmarks.md +++ b/.claude/ci/benchmarks.md @@ -4,11 +4,13 @@ **Source:** - `.gitlab/generate-package.php` — declares `include: .gitlab/benchmarks.yml` and the pipeline stages -- `.gitlab/benchmarks.yml` — all benchmark job definitions (if present; may be in the `DataDog/benchmarking-platform` repo instead) +- `.gitlab/benchmarks.yml` — all benchmark job definitions; the microbenchmark + steps, container and gate configs live in `.gitlab/benchmarks/` (see + `.gitlab/benchmarks/README.md`) | CI Job | Image | What it does | |--------|-------|--------------| -| `benchmarks-tracer` | `486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:dd-trace-php-82-dev` | Runs PHP tracer microbenchmarks via the `benchmarking-platform` framework; skips automatically if no tracer-relevant files changed | +| `benchmarks-tracer` | `$MICROBENCHMARKS_CI_IMAGE` (see `.gitlab/benchmarks.yml`; built in-repo from `.gitlab/benchmarks/container/`) | Runs PHP tracer microbenchmarks via the Benchmarking Platform framework; skips automatically if no tracer-relevant files changed | | `benchmarks-appsec` | same | Runs appsec microbenchmarks; produces `candidate.tar.gz` and `baseline.tar.gz` artifacts | | `benchmarks-profiler` | same | Runs profiler microbenchmarks | | `macrobenchmarks: [{PHP_VERSION}]` | `486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:php_laravel-realworld` | Runs a Laravel Realworld application under k6 load at three traffic levels; PHP 7.4 and 8.1 | @@ -34,7 +36,7 @@ Runner: `runner:apm-k8s-tweaked-metal` (microbenchmarks); `runner:apm-k8s-same-c ## What It Tests Microbenchmarks measure overhead of the tracer, appsec, and profiler components -using the `DataDog/benchmarking-platform` framework (`dd-trace-php` branch). The +using the Benchmarking Platform framework (steps in `.gitlab/benchmarks/`). The scenario name is passed as `BP_SCENARIO` to `bp-runner`. Macrobenchmarks run a realistic PHP application (Laravel Realworld) under k6 load @@ -55,7 +57,7 @@ dev container. ### Running the benchmarks -The `benchmarking-platform` repo (branch `dd-trace-php`) is only the +The `.gitlab/benchmarks/` directory is only the CI orchestrator — it calls `make benchmarks` and friends. You do not need `bp-runner` for local runs. Three approaches, from simplest to most flexible: @@ -179,8 +181,7 @@ Or filter them out: ## Investigating a Regression When `check-big-regressions` fails, download the `reports/` artifact from the -`benchmarks-tracer` job. The gate runs `bp-runner.fail-on-regression.yml` from the -`benchmarking-platform` repo (cloned into `/platform`). To read the job log directly: +`benchmarks-tracer` job. The gate runs `.gitlab/benchmarks/bp-runner.fail-on-regression.yml`. To read the job log directly: ```bash curl -s -H "PRIVATE-TOKEN: $GITLAB_PERSONAL_ACCESS_TOKEN" \ @@ -196,7 +197,7 @@ curl -s -H "PRIVATE-TOKEN: $GITLAB_PERSONAL_ACCESS_TOKEN" \ - The macrobenchmark image (`php_laravel-realworld`) is maintained on the `php/laravel-realworld` branch of `DataDog/benchmarking-platform`, distinct from - the microbenchmark image (`dd-trace-php` branch). + the microbenchmark image (built in-repo from `.gitlab/benchmarks/container/`). - The PHP extension dir (`/opt/php/...`) is outside the overlayfs project tree, so `ddtrace.so` must be installed into it on every diff --git a/.gitlab/BENCHMARKS.md b/.gitlab/BENCHMARKS.md deleted file mode 100644 index ad24ce9f71f..00000000000 --- a/.gitlab/BENCHMARKS.md +++ /dev/null @@ -1,60 +0,0 @@ -# Benchmarks - -GitLab CI configuration for the benchmarks that run on the -[Benchmarking Platform](https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/2419261562/Benchmarking+Platform). - -## Layout - -All benchmark jobs are defined in `benchmarks.yml`. - -- `benchmarks-tracer`, `benchmarks-profiler`, `benchmarks-appsec`: microbenchmarks, extend - `.microbenchmarks`. - - Run on a dedicated bare-metal runner, then convert, upload and comment on the PR. - - Steps live in the `dd-trace-php` branch of - [benchmarking-platform](https://github.com/DataDog/benchmarking-platform). - - `check-big-regressions` gates `benchmarks-tracer` on regressions above the threshold - defined on `bp-runner.fail-on-regression.yml`. -- `macrobenchmarks`: k6 load test against a sample Laravel app, extends `.macrobenchmarks`. - - Runs on `master` and on `ddtrace-*` release branches, manual elsewhere. - - Steps live in the `php/laravel-realworld` branch of - [benchmarking-platform](https://github.com/DataDog/benchmarking-platform). - - `check-slo-breaches` gates releases based on SLOs defined on `bp-runner.fail-on-breach.yml`. -- `dsm-throughput`: Data Streams Monitoring overhead on Kafka and RabbitMQ - produce/consume workloads, against real brokers and agent. - - Runs when the Kafka or AMQP integration or DSM code changes, manual - elsewhere; allowed to fail. - - Steps live in the `php/data-streams-monitoring` branch of - [benchmarking-platform](https://github.com/DataDog/benchmarking-platform), - which follows the other tracers' `/data-streams-monitoring` - suites. - - Fails if DSM adds more than 3% duration or memory on top of APM, for - either broker. -- `linux-php-laravel-realworld-parallel`, `linux-php-symfony-realworld-parallel`, - `linux-php-wordpress-parallel`: included from - [apm-sdks-benchmarks](https://github.com/DataDog/apm-sdks-benchmarks/tree/main/.gitlab). - - Change them there. - - `benchmarks.yml` applies `macrobenchmarks-rules` to the run jobs and to - their `generate-slos`, `check-slo-breaches` and `upload-results` - follow-up jobs, which consume the run jobs' artifacts. - -## Marking a benchmark as flaky - -Add it to `FLAKY_BENCHMARKS_REGEX` in the suite's job or template: - -- Microbenchmarks (`benchmarks-tracer`, `benchmarks-profiler`, `benchmarks-appsec`): - `variables` in `.microbenchmarks` in `benchmarks.yml`. -- Macrobenchmarks (`macrobenchmarks`): `variables` in `.macrobenchmarks` in `benchmarks.yml`. - -The benchmark still runs and reports, but doesn't fail performance quality gates: -`check-big-regressions` (percentage-based) and `check-slo-breaches` (SLO-based). - -- The regex matches anywhere in the scenario name. - - `SpanBench` quarantines every `SpanBench` scenario. - - Anchor with `^...$` to target one scenario. - -```yaml -FLAKY_BENCHMARKS_REGEX: "SpanBench|^webserver--laravel-realworld--baseline--none--normal_operation$" -``` - -Open a ticket to fix or remove it. See -[Flaky Benchmarks Monitoring](https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/7223313012/Flaky+Benchmarks+Monitoring). diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index d28b58d0617..e1b199f9337 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -1,4 +1,6 @@ include: + - project: 'DataDog/benchmarking-platform-tools' + file: 'images/templates/gitlab/build-ci-images.template.yml' - project: 'DataDog/benchmarking-platform-tools' file: 'images/templates/gitlab/check-slo-breaches.template.yml' - project: 'DataDog/benchmarking-platform-tools' @@ -105,9 +107,16 @@ php-wordpress-parallel-upload-results: rules: *macrobenchmarks-rules variables: - BASE_CI_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:dd-trace-php-82-dev - # The Dockerfile to this image is located at: - # https://github.com/DataDog/benchmarking-platform/tree/dd-trace-php + # Microbenchmarks CI image, consumed by the benchmark jobs below. Repin to the + # tag pushed by a `build-benchmark-ci-images` run after changing anything in + # `.gitlab/benchmarks/container/` (see `.gitlab/benchmarks/README.md`). + MICROBENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-php-152770667 + # The Dockerfile is located at: .gitlab/benchmarks/container/Dockerfile + # Image build, consumed by the included build-ci-images template. The per-pipeline + # suffix pins each build to a unique tag so a rebuild can't shift what older + # pipelines pulled. + BASE_CI_IMAGE_SUFFIX: dd-trace-php-${CI_PIPELINE_ID} + BASE_CI_IMAGE_CONTAINER_DIR: .gitlab/benchmarks/container MACROBENCHMARKS_CI_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:php_laravel-realworld # The Dockerfile to this image is located at: # https://github.com/DataDog/benchmarking-platform/tree/php/laravel-realworld @@ -115,6 +124,11 @@ variables: # The Dockerfile to this image is located at: # https://github.com/DataDog/benchmarking-platform/tree/php/data-streams-monitoring +# 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 + workflow: auto_cancel: on_new_commit: interruptible @@ -201,10 +215,14 @@ workflow: tags: ["runner:apm-k8s-tweaked-metal"] needs: [] image: - name: $BASE_CI_IMAGE + name: $MICROBENCHMARKS_CI_IMAGE timeout: 90m script: + # Keep the prelude: the gate and the bp-runner configs both depend on + # ARTIFACTS_DIR pointing at reports/ and on github.com/DataDog being + # rewritten to gitlab.ddbuild.io for the benchmark checkouts. - 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/" - | # Allows benchmark flakiness monitoring pipelines to run this job. # See https://github.com/DataDog/benchmarking-platform-tools/tree/main/scripts/stability#stability-monitoring-ci. @@ -219,15 +237,12 @@ workflow: fi echo "Tracer-related file changes detected - proceeding with benchmarks" fi - - git clone --branch dd-trace-php https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/benchmarking-platform /platform && cd /platform - - ./steps/capture-hardware-software-info.sh - # Keep submodules at the selected candidate and baseline revisions. + # Keep submodules at the selected candidate and baseline revisions. The + # whole flow (agent, one-time setup, run, analyze, S3) is driven by the + # bp-runner config; baseline resolution is bp-runner's auto lookup. - >- GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=submodule.recurse GIT_CONFIG_VALUE_0=true - BP_SCENARIO=$SCENARIO bp-runner bp-runner.yml --debug -t - - ./steps/analyze-results.sh - - "./steps/upload-results-to-s3.sh || :" - - "./steps/post-pr-comment.sh || :" + BP_SCENARIO=$SCENARIO bp-runner "${CI_PROJECT_DIR}/.gitlab/benchmarks/bp-runner.yml" --debug -t artifacts: name: "reports" paths: @@ -243,6 +258,13 @@ workflow: DD_SIDECAR_DISABLE_DIRECT_EXEC: 1 # See https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/7223313012/Flaky+Benchmarks+Monitoring for more details. FLAKY_BENCHMARKS_REGEX: "" + # Benchmark analyzer settings, previously exported by + # steps/config-benchmark-analyzer.sh. Every bp-runner step inherits the CI + # process environment, so the settings live here instead of the config. + UNCONFIDENCE_THRESHOLD: "2.0" + DISABLE_NHST: "1" + CI_TYPE: "theoretical" + MD_REPORT_ONLY_CHANGES: "1" benchmarks-profiler: extends: .microbenchmarks @@ -266,15 +288,58 @@ benchmarks-tracer: benchmarks-appsec: extends: .microbenchmarks rules: *benchmarks-appsec-rules + # reports/ is needed by benchmarks-pr-comment (like the other scenarios); + # the log tarballs are the scenario's own diagnostics. artifacts: - name: "logs" + name: "reports" + when: always paths: + - reports/ - candidate.tar.gz - baseline.tar.gz - expire_in: 2 days + expire_in: 3 months variables: SCENARIO: "appsec" +# Posts the benchmark comparison on the PR and uploads the results to the +# Benchmarking Platform API, for whichever of the three scenarios ran in this +# pipeline (their reports/ artifacts are all collected here). Allow-failure +# keeps a broken upload or a missing PR from blocking the gate, preserving the +# old `|| :` semantics, and running it in a separate job avoids the +# parallel-teardown race with the S3 upload. +benchmarks-pr-comment: + stage: benchmarks-report + # Only the always-running job may be needed here: a manual job that is + # present but not run makes GitLab skip the dependent. + needs: + - benchmarks-tracer + allow_failure: true + when: on_success + tags: ["arch:amd64"] + image: $MICROBENCHMARKS_CI_IMAGE + timeout: 30m + rules: *benchmarks-tracer-rules + variables: + # See https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/7223313012/Flaky+Benchmarks+Monitoring for more details. + FLAKY_BENCHMARKS_REGEX: "" + # Benchmark analyzer settings, previously exported by + # steps/config-benchmark-analyzer.sh. The PR comment's comparison output + # depends on them. + UNCONFIDENCE_THRESHOLD: "2.0" + DISABLE_NHST: "1" + CI_TYPE: "theoretical" + MD_REPORT_ONLY_CHANGES: "1" + 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/" + - bp-runner "${CI_PROJECT_DIR}/.gitlab/benchmarks/bp-runner.pr-comment.yml" --debug + artifacts: + name: "reports" + when: always + paths: + - reports/ + expire_in: 3 months + # Kafka and RabbitMQ produce/consume throughput with Data Streams Monitoring # off and on, against real brokers and agent; fails if DSM adds more than 3% # duration or memory on top of APM for either broker. Same methodology as the other tracers' @@ -336,12 +401,8 @@ check-big-regressions: else echo "Reports directory found with content - running regression check" 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-php https://github.com/DataDog/benchmarking-platform /platform - export PATH="$PATH:/platform/steps" - bp-runner /platform/bp-runner.fail-on-regression.yml --debug + export PATH="$PATH:${CI_PROJECT_DIR}/.gitlab/benchmarks/steps" + bp-runner "${CI_PROJECT_DIR}/.gitlab/benchmarks/bp-runner.fail-on-regression.yml" --debug fi variables: # Gitlab and BP specific env vars. Do not modify. diff --git a/.gitlab/benchmarks/README.md b/.gitlab/benchmarks/README.md new file mode 100644 index 00000000000..54986304786 --- /dev/null +++ b/.gitlab/benchmarks/README.md @@ -0,0 +1,190 @@ +# Microbenchmarks + +The microbenchmark jobs run the PHP tracer's, AppSec's and the profiler's +benchmark suites inside the Datadog +[Benchmarking Platform](https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/2419261562/Benchmarking+Platform) +and compare the results against a baseline to detect performance regressions +on every PR. + +This directory holds everything the microbenchmark jobs need: + +- **`container/`** — Dockerfile for the `MICROBENCHMARKS_CI_IMAGE` CI image, + built in-repo via the + [`build-ci-images.template.yml`](https://github.com/DataDog/benchmarking-platform-tools/blob/main/images/templates/gitlab/build-ci-images.template.yml) + include (see [How to rebuild the CI Docker image](#how-to-rebuild-the-ci-docker-image)). +- **`steps/`** — `update-dd-agent-config.sh`, the config script of the + `datadog_agent` step (bp-runner has no `update_dd_agent_config` step type). +- **`bp-runner.yml`** — [bp-runner](https://github.com/DataDog/benchmarking-platform-tools/tree/main/bp-runner) + experiment definition: captures hardware/software info, starts a local + Datadog agent, does the one-time setup (ini appends, mysql and redis start, + sysctl), clones the candidate and the baseline and runs `benchmark/runall.sh` + on pinned CPUs, converts the results per framework (PHPBench, tea's Google + Benchmark, Sirun), and uploads the reports to S3. +- **`bp-runner.pr-comment.yml`** — posts the comparison on the PR and uploads + the converted results to the Benchmarking Platform API (run by the separate + `benchmarks-pr-comment` job). +- **`bp-runner.fail-on-regression.yml`** — gate config used by + `check-big-regressions` to fail the pipeline on regressions above its + threshold. + +The jobs themselves (`benchmarks-tracer`, `benchmarks-appsec`, +`benchmarks-profiler`, `check-big-regressions`) are defined in +[`.gitlab/benchmarks.yml`](../benchmarks.yml), which runs as a child pipeline +of `package-trigger` (the stage list it validates against is generated by +`.gitlab/generate-package.php`). + +Execution flow on each PR: + +1. Each benchmark job sets `SCENARIO` (`tracer`, `appsec` or `profiler`) and + runs `bp-runner .gitlab/benchmarks/bp-runner.yml`: hardware/software info + capture, Datadog agent, one-time setup, then the candidate and baseline + runs (the baseline is the PR's merge-target branch, at the merge base, + resolved by bp-runner's auto lookup). +2. Each run's `benchmark/` suite results are saved as + `reports/$BASELINE_OR_CANDIDATE-.` artifacts, with the logs + tarred as `candidate.tar.gz`/`baseline.tar.gz`. +3. The config's analyze steps convert the results per framework (PHPBench, + GoogleBenchmark for tea, Sirun) and the S3 teardown archives the reports; + `benchmarks-pr-comment` runs `bp-runner.pr-comment.yml` to push the + converted results to the Benchmarking Platform API so they land on the + project's trend series. +4. `check-big-regressions` gates the pipeline on regressions above the + threshold in `bp-runner.fail-on-regression.yml`, and + `benchmarks-pr-comment` comments the comparison on the PR. + +## How to add a new microbenchmark + +Where a benchmark lives depends on the scenario it belongs to: + +- **tracer / appsec** (`benchmarks-tracer`, `benchmarks-appsec`): PHPBench + suites in [`tests/Benchmarks/`](../../tests/Benchmarks/) — + tracer benchmarks in the default groups, AppSec ones under the + `frameworks` group (`BENCHMARK_EXTRA="--group=frameworks"`). +- **tracer, tea** (`benchmarks-tracer`): C++ Google Benchmark suite in + [`tea/benchmarks/`](../../tea/benchmarks/). +- **profiler** (`benchmarks-profiler`): sirun suites in + [`profiling/benches/`](../../profiling/benches/), run through + [`benchmark/runall.sh`](../../benchmark/runall.sh) with a natively compiled + profiler. + +1. Add the benchmark in the matching location, following the existing + patterns there. +2. Run it locally the same way the job does (see + [How to run the suite locally](#how-to-run-the-suite-locally)). +3. Push the branch and let the benchmark job run: new benchmarks are picked + up automatically — the scenarios are discovered from the suites' own + result files, not from a list. On the first run the baseline may not + contain the new benchmark, so it appears as candidate-only in the + comparison. + +## How to update an existing microbenchmark + +Edit the benchmark where it lives (see above). Keep in mind that the baseline +run executes the *baseline checkout's* copy of the suite, so a benchmark that +was renamed or removed on the candidate is still measured on the baseline; +expect a one-run mismatch on renames. If the benchmark becomes unstable while +you iterate, see +[How to mark a benchmark as known flaky](#how-to-mark-a-benchmark-as-known-flaky). + +Changes that only affect CI plumbing (this directory, `.gitlab/benchmarks.yml`) +don't need a benchmark run: the benchmark jobs only auto-run when +tracer-relevant paths change, and can be triggered manually from the pipeline +otherwise. + +## How to mark a benchmark as known flaky + +Add it to `FLAKY_BENCHMARKS_REGEX` in the `.microbenchmarks` template's +`variables` in [`.gitlab/benchmarks.yml`](../benchmarks.yml). The benchmark +still runs and reports, but doesn't fail performance quality gates +(`check-big-regressions` here, percentage-based; `check-slo-breaches` for the +macrobenchmarks, SLO-based). + +- The regex matches anywhere in the scenario name. + - `SpanBench` quarantines every `SpanBench` scenario. + - Anchor with `^...$` to target one scenario. + +```yaml +FLAKY_BENCHMARKS_REGEX: "SpanBench|^webserver--laravel-realworld--baseline--none--normal_operation$" +``` + +Open a ticket to fix or remove it. See +[Flaky Benchmarks Monitoring](https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/7223313012/Flaky+Benchmarks+Monitoring). + +## How to rebuild the CI Docker image + +The `MICROBENCHMARKS_CI_IMAGE` used by the microbenchmark jobs is built from +`container/Dockerfile` in this directory. Rebuild and repin it whenever you +change anything in that directory (e.g. bumping PHP, adding system packages, +or updating `sirun`). + +1. Edit the relevant file(s) under `.gitlab/benchmarks/container/`. Push the + branch and open a PR. + +2. The pipeline includes + [`build-ci-images.template.yml`](https://github.com/DataDog/benchmarking-platform-tools/blob/main/images/templates/gitlab/build-ci-images.template.yml), + which defines a manual `build-benchmark-ci-images` job that builds the + image from `BASE_CI_IMAGE_CONTAINER_DIR` (`.gitlab/benchmarks/container`) + and pushes it as + `registry.ddbuild.io/ci/benchmarking-platform:$BASE_CI_IMAGE_SUFFIX` + (`dd-trace-php-` — one unique tag per pipeline, so a rebuild + can't shift what older pipelines pulled). + +3. Open the pipeline on + [gitlab.ddbuild.io/DataDog/dd-trace-php](https://gitlab.ddbuild.io/DataDog/dd-trace-php) + (the `package-trigger` child pipeline), play the + `build-benchmark-ci-images` job, wait for it to finish, and copy the + resulting image tag from its logs. + +4. Repin `MICROBENCHMARKS_CI_IMAGE` in `.gitlab/benchmarks.yml` to that tag: + + ```yaml + # Built here: + MICROBENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-php- + ``` + +5. Push the update. The microbenchmarks now run against the rebuilt image. + Verify a green benchmark pipeline before merging. + +## How to run the suite locally + +The suites themselves live in the tracer repository, so the quick feedback +loop is to run them the way `benchmark/runall.sh` does, without the +Benchmarking Platform wrapper: + +- tracer / appsec (PHPBench, see `benchmark/runall.sh`): + ```bash + make composer_tests_update # once, to install benchmark dependencies + make benchmarks # tracer PHPBench scenarios + make benchmarks_opcache # the same scenarios under OPCache + make benchmarks_tea # the C++ Google Benchmark suite + # AppSec adds: make install_appsec, then + # BENCHMARK_EXTRA="--group=frameworks" make call_benchmarks + ``` +- profiler: `SCENARIO=profiler ./benchmark/runall.sh` from the repo root + (sirun drives `profiling/benches/timeline.json` and + `profiling/benches/exceptions.json` after a natively compiled profiler — + see `benchmark/run_with_native_profiler.sh`). + +To reproduce a full CI run including the baseline comparison, run the job's +steps from the repository root with the environment the CI job provides +(`SCENARIO`/`BP_SCENARIO`, `ARTIFACTS_DIR`): + +```bash +export ARTIFACTS_DIR="$(pwd)/reports" +SCENARIO=tracer BP_SCENARIO=tracer bp-runner .gitlab/benchmarks/bp-runner.yml --debug -t +``` + +Note that `bp-runner.yml` starts a real Datadog agent (the API key comes from +AWS SSM in CI, set `DD_API_KEY` yourself locally), needs a GitHub token for +the baseline lookup, and pins the benchmark CPUs (26-47 on the 48-core CI +runners), so a faithful local run needs a comparable machine. + +## Other benchmark suites (not in this directory) + +- `macrobenchmarks` and the `linux-php-*-parallel` jobs: defined in + `.gitlab/benchmarks.yml` but their steps still live in the + `php/laravel-realworld` branch of + [benchmarking-platform](https://github.com/DataDog/benchmarking-platform) + and in [apm-sdks-benchmarks](https://github.com/DataDog/apm-sdks-benchmarks/tree/main/.gitlab). +- `dsm-throughput`: steps live in the `php/data-streams-monitoring` branch of + benchmarking-platform. 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 00000000000..c0d1ae13635 --- /dev/null +++ b/.gitlab/benchmarks/bp-runner.fail-on-regression.yml @@ -0,0 +1,6 @@ +experiments: + - name: Run regression check + steps: + - name: Regression Check + run: fail_on_regression + regression_threshold: 10.0 # percents \ No newline at end of file diff --git a/.gitlab/benchmarks/bp-runner.pr-comment.yml b/.gitlab/benchmarks/bp-runner.pr-comment.yml new file mode 100644 index 00000000000..c0c9d5f8bc3 --- /dev/null +++ b/.gitlab/benchmarks/bp-runner.pr-comment.yml @@ -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-php diff --git a/.gitlab/benchmarks/bp-runner.yml b/.gitlab/benchmarks/bp-runner.yml new file mode 100644 index 00000000000..a5afa5d9043 --- /dev/null +++ b/.gitlab/benchmarks/bp-runner.yml @@ -0,0 +1,150 @@ +# Analyzer settings (UNCONFIDENCE_THRESHOLD, DISABLE_NHST, CI_TYPE, +# MD_REPORT_ONLY_CHANGES) live in the CI job's `variables:`, not here. +# bp-runner configs have no top-level `env:`, and experiment env does not +# reach teardown steps. Every step inherits the CI process environment. + +global_setup: + - name: Capture hardware/software info + run: collect_hardware_software_info + +experiments: + - name: microbenchmarks + # Environment previously exported once by steps/run-benchmarks.sh before + # the runs. `unset CI` from the old script lives in the run script below, + # where it takes effect; the experiment env cannot unset variables. + env: + COMPOSER_ALLOW_SUPERUSER: "1" + DD_TRACE_AUTOLOAD_NO_COMPILE: "true" + CFLAGS: "-O2 -falign-functions=64" + RUN_WEB_BENCHES_WITH_DDPROF: "1" + setup: + - name: datadog-agent + run: datadog_agent + cpus: 24-25 + config_sh: .gitlab/benchmarks/steps/update-dd-agent-config.sh + + # One-time setup only. run_microbenchmarks executes the run script once + # for the candidate and once for the baseline, so the ini appends, the + # mysql/redis start and the sysctl must NOT live there. + - name: one-time setup + run: shell + cpus: 26-47 + script: | + set -ex + + # The built-in capture step doesn't know about PHP; keep the PHP + # version capture steps/capture-hardware-software-info.sh used to do. + (which php && php -v > "$ARTIFACTS_DIR/php.txt") || : + + if [ "$BP_SCENARIO" = "tracer" ] || [ "$BP_SCENARIO" = "appsec" ]; then + echo "extension=ddtrace.so" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini + if [ "$BP_SCENARIO" = "appsec" ]; then + echo "extension=ddappsec.so" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini + echo "datadog.appsec.cli_start_on_rinit=true" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini + echo "datadog.appsec.helper_path=$(PHP_EXTENSION_DIR)/libddappsec-helper.so" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini + echo "datadog.appsec.rules=/tmp/recommended.json" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini + echo "datadog.appsec.helper_socket_path=/tmp/ddappsec.sock" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini + echo "datadog.appsec.helper_lock_path=/tmp/ddappsec.lock" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini + echo "datadog.appsec.log_file=/tmp/logs/appsec.log" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini + echo "datadog.appsec.helper_log_file=/tmp/logs/helper.log" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini + fi + taskset -c 26-29 service mysql start + taskset -c 30-33 redis-server --daemonize yes + fi + + echo "127.0.0.1 mysql-integration" >> /etc/hosts + echo "127.0.0.1 redis-integration" >> /etc/hosts + + echo "display_errors=stderr" >> /etc/php/8.2/cli/php.ini + echo "error_log=/tmp/logs/php-error.log" >> /etc/php/8.2/cli/php.ini + echo "display_startup_errors=1" >> /etc/php/8.2/cli/php.ini + echo "display_errors=stderr" >> /etc/php/8.2/cgi/conf.d/php.ini + echo "error_log=/tmp/logs/php-error-cgi.log" >> /etc/php/8.2/cgi/conf.d/php.ini + echo "display_startup_errors=1" >> /etc/php/8.2/cgi/conf.d/php.ini + + # Ensure ddprof can run + if ! sysctl -w kernel.perf_event_paranoid=2; then + echo -e "\e[41mERROR: Failed to set kernel.perf_event_paranoid to 2. This is required by ddprof.\e[0m" + echo -e "\e[41mPlease check if the container is running with --privileged.\e[0m" + exit 1 + fi + + steps: + - name: Run benchmarks + run: run_microbenchmarks + repo: DataDog/dd-trace-php + cpus: 26-47 + # The default fetch does not initialise submodules, and the suites need + # the libdatadog and google-benchmark submodules. The clone follows the + # branch tip, so the submodules must be re-synced after the SHA checkout. + how_to_fetch_release: | + git clone --recurse-submodules --branch $BRANCH https://github.com/DataDog/dd-trace-php/ "$CODE_SRC" + cd "$CODE_SRC" && git checkout $COMMIT_SHA + git submodule update --init --recursive + # Runs once per release: bp-runner sets CODE_SRC, BRANCH, COMMIT_SHA and + # BASELINE_OR_CANDIDATE (candidate first, then the baseline at the merge + # base, with baseline resolution left to bp-runner's auto lookup). + # runall.sh writes fixed, unprefixed names into $ARTIFACTS_DIR; this + # script renames each result to + # $ARTIFACTS_DIR/$BASELINE_OR_CANDIDATE-. — the layout the + # analyze steps below and the fail-on-regression gate glob — gives the + # OPCache and AppSec subjects their distinguishing suffixes, and tars + # the run's logs. + how_to_run_benchmarks: | + export SCENARIO=$BP_SCENARIO + unset CI + + GITLAB_ARTIFACTS_PATH="/go/src/github.com/DataDog/apm-reliability/dd-trace-php/" + + cd "$CODE_SRC/benchmark/" + rm -rf /tmp/logs/ + mkdir -p /tmp/logs + taskset -c 34-47 ./runall.sh + + if [ "$SCENARIO" = "profiler" ]; then + mv "$ARTIFACTS_DIR/sirun_timeline.ndjson" "$ARTIFACTS_DIR/$BASELINE_OR_CANDIDATE-sirun_timeline.ndjson" + mv "$ARTIFACTS_DIR/sirun_exceptions.ndjson" "$ARTIFACTS_DIR/$BASELINE_OR_CANDIDATE-sirun_exceptions.ndjson" + elif [ "$SCENARIO" = "tracer" ]; then + # Give the OPCache subjects an "-opcache" suffix so they don't + # collide with the non-OPCache subjects (third column is the subject). + awk -F ',' -v OFS=',' 'NR == 1 { print } NR > 1 { $3 = $3 "-opcache"; print }' \ + "$ARTIFACTS_DIR/tracer-bench-results-opcache.csv" > "$ARTIFACTS_DIR/tracer-bench-results-opcache.tmp" && \ + mv "$ARTIFACTS_DIR/tracer-bench-results-opcache.tmp" "$ARTIFACTS_DIR/$BASELINE_OR_CANDIDATE-tracer-bench-results-opcache.csv" + mv "$ARTIFACTS_DIR/tracer-bench-results.csv" "$ARTIFACTS_DIR/$BASELINE_OR_CANDIDATE-tracer-bench-results.csv" + mv "$ARTIFACTS_DIR/tracer-tea-bench-results.json" "$ARTIFACTS_DIR/$BASELINE_OR_CANDIDATE-tracer-tea-bench-results.json" + elif [ "$SCENARIO" = "appsec" ]; then + # Give the AppSec subjects an "-appsec" suffix so they don't collide + # with the tracer subjects (third column is the subject). + awk -F ',' -v OFS=',' 'NR == 1 { print } NR > 1 { $3 = $3 "-appsec"; print }' \ + "$ARTIFACTS_DIR/appsec-bench-results.csv" > "$ARTIFACTS_DIR/appsec-bench-results.tmp" && \ + mv "$ARTIFACTS_DIR/appsec-bench-results.tmp" "$ARTIFACTS_DIR/$BASELINE_OR_CANDIDATE-appsec-bench-results.csv" + fi + + # Save all logs as artifacts + tar -zcvf "$GITLAB_ARTIFACTS_PATH/$BASELINE_OR_CANDIDATE.tar.gz" /tmp/logs + rm -rf /tmp/logs + + # One analyze step per framework; each step no-ops on the scenarios + # whose result files its filter doesn't match. + - name: Analyze PHPBench results + run: analyze_microbenchmarks + framework: PHPBench + input_filter_pattern: $ARTIFACTS_DIR/$BASELINE_OR_CANDIDATE-*-bench-results*.csv + group_by_pattern: '^(.*)\.csv$' + + - name: Analyze tea results + run: analyze_microbenchmarks + framework: GoogleBenchmark + input_filter_pattern: $ARTIFACTS_DIR/$BASELINE_OR_CANDIDATE-tracer-tea-bench-results.json + + - name: Analyze sirun results + run: analyze_microbenchmarks + framework: Sirun + input_filter_pattern: $ARTIFACTS_DIR/$BASELINE_OR_CANDIDATE-sirun_*.ndjson + group_by_pattern: '^(.*)\.ndjson$' + + teardown: + - name: Upload to S3 + run: upload_to_s3 + # If BP_EXTERNAL_S3_URL is empty, bp-runner uses its default S3 destination. + url: $BP_EXTERNAL_S3_URL diff --git a/.gitlab/benchmarks/container/Dockerfile b/.gitlab/benchmarks/container/Dockerfile new file mode 100644 index 00000000000..4ee33dd0acb --- /dev/null +++ b/.gitlab/benchmarks/container/Dockerfile @@ -0,0 +1,117 @@ +FROM registry.ddbuild.io/images/benchmarking-platform-tools-ubuntu:latest + +ARG CI_JOB_TOKEN +ARG RUST_VERSION=1.91.1 + +# Install MySQL & create a test database (User: test, Password: test, Database: test) +RUN --mount=type=ssh bp-install mysql && apt-get install --no-install-recommends -y mysql-client + +# Install ddprof & the agent for ddprof submission +RUN --mount=type=ssh bp-install ddprof datadog-agent + +# Install sirun to run performance tests +RUN curl -o sirun.tar.gz -L https://github.com/DataDog/sirun/releases/download/v0.1.10/sirun-v0.1.10-x86_64-unknown-linux-musl.tar.gz \ + && tar -xzf sirun.tar.gz \ + && rm sirun.tar.gz \ + && mv sirun /usr/bin/sirun + +# Get an LLVM toolchain for cross-language LTO: +# https://doc.rust-lang.org/rustc/linker-plugin-lto.html +RUN apt-get update \ + && apt-get install --no-install-recommends -y \ + apt-transport-https \ + ca-certificates \ + lsb-release \ + software-properties-common \ + gnupg \ + gpg \ + && (wget --no-check-certificate -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -) \ + && add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main" \ + && apt-get install --no-install-recommends -y \ + clang-16 \ + libclang-16-dev \ + lld-16 \ + llvm-16-dev + +# Dependencies for building PHP extensions +RUN apt-get update \ + && apt-get install --no-install-recommends -y \ + libcurl4-gnutls-dev \ + libsodium-dev \ + libargon2-0-dev + +# Get an assortment of tools including PHP and Rust +RUN apt-get update \ + && add-apt-repository ppa:ondrej/php \ + && sed -i 's/main$/main main\/debug/' /etc/apt/sources.list.d/ondrej* \ + && apt-get update \ + && apt-get install --no-install-recommends -y \ + sudo \ + git \ + hwinfo \ + jq \ + nginx \ + php8.2 \ + php8.2-dev \ + php8.2-common-dbgsym \ + php8.2-cli-dbgsym \ + php8.2-cgi \ + php8.2-cgi-dbgsym \ + php8.2-curl \ + php8.2-dom \ + php8.2-fpm \ + php8.2-iconv \ + php8.2-mbstring \ + php8.2-mysql \ + php8.2-xml \ + php8.2-zip \ + libphp8.2-embed \ + valgrind \ + xz-utils \ + && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${RUST_VERSION} --profile minimal + +RUN apt-get install -y php-pear + +RUN iniDir=$(php -i | awk -F"=> " '/Scan this dir for additional .ini files/ {print $2}') \ + && pecl install redis-5.3.7 \ + && echo "extension=redis.so" > $iniDir/redis.ini + +RUN extDir=$(php -r 'print ini_get("extension_dir");') \ + && ln -s $extDir/redis.so $extDir/redis-5.3.7.so + +# Install Composer +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +# Install Redis 5.0 from source +RUN apt-get install --no-install-recommends -y \ + build-essential \ + tcl \ + && curl -o redis.tar.gz -L http://download.redis.io/releases/redis-5.0.10.tar.gz \ + && tar -xzf redis.tar.gz \ + && rm redis.tar.gz \ + && cd redis-5.0.10 \ + && make \ + && sudo make install \ + && cd .. \ + && rm -rf redis-5.0.10 + +ENV CMAKE_VERSION="3.24.4" + +# Install CMake +RUN set -eux; \ + if [ "$(uname -m)" = "aarch64" ]; then \ + CMAKE_SHA256="86f823f2636bf715af89da10e04daa476755a799d451baee66247846e95d7bee"; \ + else \ + CMAKE_SHA256="cac77d28fb8668c179ac02c283b058aeb846fe2133a57d40b503711281ed9f19"; \ + fi; \ + cd /tmp && curl -L --output cmake.tar.gz https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-Linux-$(uname -m).tar.gz; \ + (echo "${CMAKE_SHA256} cmake.tar.gz" | sha256sum -c -); \ + mkdir -p /opt/cmake/${CMAKE_VERSION}; \ + tar --strip-components 1 -C /opt/cmake/${CMAKE_VERSION} -xf /tmp/cmake.tar.gz; \ +# Currently there's only one version of cmake, make it default + ln -s /opt/cmake/${CMAKE_VERSION}/bin/cmake /usr/local/bin/cmake; \ + rm -rfv /tmp/* + +ENV PATH=/root/.cargo/bin:$PATH +ENV DD_PROFILING_OUTPUT_PPROF=/tmp/foo.pprof +WORKDIR /app diff --git a/.gitlab/benchmarks/steps/update-dd-agent-config.sh b/.gitlab/benchmarks/steps/update-dd-agent-config.sh new file mode 100755 index 00000000000..880e1c579c5 --- /dev/null +++ b/.gitlab/benchmarks/steps/update-dd-agent-config.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +set -e + +export DD_HOSTNAME="$(hostname)" +if [ -z "$DD_API_KEY" ]; then + export DD_API_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.$CI_PROJECT_NAME.dd_api_key --with-decryption --query "Parameter.Value" --out text) +fi + +mkdir -p /etc/datadog-agent +cat < /etc/datadog-agent/datadog.yaml +api_key: $DD_API_KEY +hostname: $DD_HOSTNAME +site: datadoghq.com + +tags: + - bp_app:microbenchmarks + - bp_branch:$CI_COMMIT_REF_NAME + - bp_commit_sha:$CI_COMMIT_SHORT_SHA + - bp_project:dd-trace-php + - ci_job_id:$CI_JOB_ID + - ci_job_name:$CI_JOB_NAME + - ci_pipeline_id:$CI_PIPELINE_ID +EOT + diff --git a/.gitlab/generate-package.php b/.gitlab/generate-package.php index 727a29c2b1a..90a1443e639 100644 --- a/.gitlab/generate-package.php +++ b/.gitlab/generate-package.php @@ -124,6 +124,7 @@ function system_tests_run_scenarios(string $scenarios): void - tracing - packaging - benchmarks + - benchmarks-report - gate - notify - verify From d68b6be8918c51b6b586cdb0c75c606db9e5a5ed Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Tue, 17 Nov 2026 13:57:38 +0100 Subject: [PATCH 02/14] ci(benchmarks): fail the run step on errors, drop the dead gate PATH export The old run-benchmarks.sh ran with set -ex; the bp-runner run script lost that in the conversion, so a failing runall.sh was masked by the trailing rm. Add set -e, derive the log tarball path from CI_PROJECT_DIR instead of the hardcoded runner checkout, and drop the steps PATH export the gate job no longer uses. --- .gitlab/benchmarks.yml | 1 - .gitlab/benchmarks/bp-runner.yml | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index e1b199f9337..d8a2086694a 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -401,7 +401,6 @@ check-big-regressions: else echo "Reports directory found with content - running regression check" export ARTIFACTS_DIR="$(pwd)/reports/" - export PATH="$PATH:${CI_PROJECT_DIR}/.gitlab/benchmarks/steps" bp-runner "${CI_PROJECT_DIR}/.gitlab/benchmarks/bp-runner.fail-on-regression.yml" --debug fi variables: diff --git a/.gitlab/benchmarks/bp-runner.yml b/.gitlab/benchmarks/bp-runner.yml index a5afa5d9043..b63158d096b 100644 --- a/.gitlab/benchmarks/bp-runner.yml +++ b/.gitlab/benchmarks/bp-runner.yml @@ -91,10 +91,11 @@ experiments: # OPCache and AppSec subjects their distinguishing suffixes, and tars # the run's logs. how_to_run_benchmarks: | + set -e export SCENARIO=$BP_SCENARIO unset CI - GITLAB_ARTIFACTS_PATH="/go/src/github.com/DataDog/apm-reliability/dd-trace-php/" + GITLAB_ARTIFACTS_PATH="$CI_PROJECT_DIR" cd "$CODE_SRC/benchmark/" rm -rf /tmp/logs/ From b818a09bf5b47a0f19e1eb93def26916cc78aa93 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Tue, 17 Nov 2026 17:06:07 +0100 Subject: [PATCH 03/14] ci(benchmarks): drop the analyzer-settings comment from the bp-runner config --- .gitlab/benchmarks/bp-runner.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.gitlab/benchmarks/bp-runner.yml b/.gitlab/benchmarks/bp-runner.yml index b63158d096b..741b2a15271 100644 --- a/.gitlab/benchmarks/bp-runner.yml +++ b/.gitlab/benchmarks/bp-runner.yml @@ -1,8 +1,3 @@ -# Analyzer settings (UNCONFIDENCE_THRESHOLD, DISABLE_NHST, CI_TYPE, -# MD_REPORT_ONLY_CHANGES) live in the CI job's `variables:`, not here. -# bp-runner configs have no top-level `env:`, and experiment env does not -# reach teardown steps. Every step inherits the CI process environment. - global_setup: - name: Capture hardware/software info run: collect_hardware_software_info From 34f093bae8701e926cc7de45f151cbf3ca99595b Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Tue, 17 Nov 2026 17:07:06 +0100 Subject: [PATCH 04/14] ci(benchmarks): drop the env comment, capitalize the setup step name --- .gitlab/benchmarks/bp-runner.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitlab/benchmarks/bp-runner.yml b/.gitlab/benchmarks/bp-runner.yml index 741b2a15271..cc8f8070c55 100644 --- a/.gitlab/benchmarks/bp-runner.yml +++ b/.gitlab/benchmarks/bp-runner.yml @@ -4,9 +4,6 @@ global_setup: experiments: - name: microbenchmarks - # Environment previously exported once by steps/run-benchmarks.sh before - # the runs. `unset CI` from the old script lives in the run script below, - # where it takes effect; the experiment env cannot unset variables. env: COMPOSER_ALLOW_SUPERUSER: "1" DD_TRACE_AUTOLOAD_NO_COMPILE: "true" @@ -21,7 +18,7 @@ experiments: # One-time setup only. run_microbenchmarks executes the run script once # for the candidate and once for the baseline, so the ini appends, the # mysql/redis start and the sysctl must NOT live there. - - name: one-time setup + - name: One-time setup run: shell cpus: 26-47 script: | From 3cae6b020dcab4d2d23750c600d6b0477d13b141 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Tue, 17 Nov 2026 17:29:55 +0100 Subject: [PATCH 05/14] docs(benchmarks): tighten comments --- .gitlab/benchmarks.yml | 20 +++++++------------- .gitlab/benchmarks/bp-runner.yml | 3 +-- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index d8a2086694a..42c8b835a9a 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -112,7 +112,7 @@ variables: # `.gitlab/benchmarks/container/` (see `.gitlab/benchmarks/README.md`). MICROBENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-php-152770667 # The Dockerfile is located at: .gitlab/benchmarks/container/Dockerfile - # Image build, consumed by the included build-ci-images template. The per-pipeline + # The per-pipeline # suffix pins each build to a unique tag so a rebuild can't shift what older # pipelines pulled. BASE_CI_IMAGE_SUFFIX: dd-trace-php-${CI_PIPELINE_ID} @@ -258,9 +258,8 @@ workflow: DD_SIDECAR_DISABLE_DIRECT_EXEC: 1 # See https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/7223313012/Flaky+Benchmarks+Monitoring for more details. FLAKY_BENCHMARKS_REGEX: "" - # Benchmark analyzer settings, previously exported by - # steps/config-benchmark-analyzer.sh. Every bp-runner step inherits the CI - # process environment, so the settings live here instead of the config. + # Analyzer settings. Every bp-runner step inherits the CI process environment, + # so the settings live here instead of the config. UNCONFIDENCE_THRESHOLD: "2.0" DISABLE_NHST: "1" CI_TYPE: "theoretical" @@ -301,12 +300,9 @@ benchmarks-appsec: variables: SCENARIO: "appsec" -# Posts the benchmark comparison on the PR and uploads the results to the -# Benchmarking Platform API, for whichever of the three scenarios ran in this -# pipeline (their reports/ artifacts are all collected here). Allow-failure -# keeps a broken upload or a missing PR from blocking the gate, preserving the -# old `|| :` semantics, and running it in a separate job avoids the -# parallel-teardown race with the S3 upload. +# Posts the comparison and uploads results. allow_failure preserves the old || : +# semantics, and a separate job avoids the parallel-teardown race with the S3 +# upload. needs only benchmarks-tracer, so only tracer results are collected. benchmarks-pr-comment: stage: benchmarks-report # Only the always-running job may be needed here: a manual job that is @@ -322,9 +318,7 @@ benchmarks-pr-comment: variables: # See https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/7223313012/Flaky+Benchmarks+Monitoring for more details. FLAKY_BENCHMARKS_REGEX: "" - # Benchmark analyzer settings, previously exported by - # steps/config-benchmark-analyzer.sh. The PR comment's comparison output - # depends on them. + # Analyzer settings the PR comment's comparison output depends on. UNCONFIDENCE_THRESHOLD: "2.0" DISABLE_NHST: "1" CI_TYPE: "theoretical" diff --git a/.gitlab/benchmarks/bp-runner.yml b/.gitlab/benchmarks/bp-runner.yml index cc8f8070c55..2aa244fd255 100644 --- a/.gitlab/benchmarks/bp-runner.yml +++ b/.gitlab/benchmarks/bp-runner.yml @@ -24,8 +24,7 @@ experiments: script: | set -ex - # The built-in capture step doesn't know about PHP; keep the PHP - # version capture steps/capture-hardware-software-info.sh used to do. + # The built-in capture step doesn't know about PHP, so capture the PHP version here. (which php && php -v > "$ARTIFACTS_DIR/php.txt") || : if [ "$BP_SCENARIO" = "tracer" ] || [ "$BP_SCENARIO" = "appsec" ]; then From 9f3ca7ee26f1355192e35019a299fadf20623be1 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Fri, 20 Nov 2026 14:19:12 +0100 Subject: [PATCH 06/14] ci(benchmarks): retry the S3 and BP API uploads The old flow ran upload-results-to-s3.sh with || :, so an upload failure could never fail the job. As a bp-runner teardown, a failed upload exits bp-runner non-zero and fails benchmarks-tracer, skipping the regression gate and the PR comment. retries_on_failure rides out transient failures; a persistent S3 outage still fails the job, unlike the old flow. --- .gitlab/benchmarks/bp-runner.pr-comment.yml | 1 + .gitlab/benchmarks/bp-runner.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitlab/benchmarks/bp-runner.pr-comment.yml b/.gitlab/benchmarks/bp-runner.pr-comment.yml index c0c9d5f8bc3..46f5c2f38f9 100644 --- a/.gitlab/benchmarks/bp-runner.pr-comment.yml +++ b/.gitlab/benchmarks/bp-runner.pr-comment.yml @@ -7,4 +7,5 @@ experiments: global_teardown: - name: Upload to BP API run: upload_to_bp_api + retries_on_failure: 3 project: dd-trace-php diff --git a/.gitlab/benchmarks/bp-runner.yml b/.gitlab/benchmarks/bp-runner.yml index 2aa244fd255..a841c6ce9e1 100644 --- a/.gitlab/benchmarks/bp-runner.yml +++ b/.gitlab/benchmarks/bp-runner.yml @@ -138,5 +138,6 @@ experiments: teardown: - name: Upload to S3 run: upload_to_s3 + retries_on_failure: 3 # If BP_EXTERNAL_S3_URL is empty, bp-runner uses its default S3 destination. url: $BP_EXTERNAL_S3_URL From 130e0e5c13e615067fe6b3effe608c03b8ac51c2 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Fri, 20 Nov 2026 14:20:03 +0100 Subject: [PATCH 07/14] ci(benchmarks): report every scenario in benchmarks-pr-comment The old per-job step posted a comment and uploaded to the BP API for all three scenarios. The new job needs only benchmarks-tracer, so appsec and profiler results no longer reached either. Add optional needs on the two manual scenario jobs: their artifacts are collected when they ran, and the job proceeds without them otherwise. The comment becomes one unified Benchmarks comment over every scenario that ran. The skip guard exits only when a tracer skip left no converted results, so a tracer skip on a stability pipeline no longer hides appsec and profiler results. --- .gitlab/benchmarks.yml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index f7dc31aaf0f..cc004bc495d 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -290,7 +290,7 @@ benchmarks-tracer: benchmarks-appsec: extends: .microbenchmarks rules: *benchmarks-appsec-rules - # reports/ is needed by benchmarks-pr-comment (like the other scenarios); + # reports/ feeds benchmarks-pr-comment (like the other scenarios); # the log tarballs are the scenario's own diagnostics. artifacts: name: "reports" @@ -305,13 +305,19 @@ benchmarks-appsec: # Posts the comparison and uploads results. allow_failure preserves the old || : # semantics, and a separate job avoids the parallel-teardown race with the S3 -# upload. needs only benchmarks-tracer, so only tracer results are collected. +# upload. benchmarks-pr-comment: stage: benchmarks-report - # Only the always-running job may be needed here: a manual job that is - # present but not run makes GitLab skip the dependent. + # Optional needs: appsec and profiler are manual on most pipelines, and a + # non-optional need on a manual job that did not run makes GitLab skip this + # job. Optional needs collect their artifacts when they ran and proceed + # without them otherwise. needs: - benchmarks-tracer + - job: benchmarks-appsec + optional: true + - job: benchmarks-profiler + optional: true allow_failure: true when: on_success tags: ["arch:amd64"] @@ -329,6 +335,14 @@ benchmarks-pr-comment: 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/" + - | + if [ -f "reports/skip-reason.txt" ] && ! ls reports/candidate*.converted.json >/dev/null 2>&1; then + echo "Benchmarks were skipped (no relevant file changes) - nothing to report" + exit 0 + elif [ -z "$(ls -A reports/ 2>/dev/null)" ]; then + echo "ERROR: Reports directory exists but is empty - benchmarks job had issues" + exit 1 + fi - bp-runner "${CI_PROJECT_DIR}/.gitlab/benchmarks/bp-runner.pr-comment.yml" --debug artifacts: name: "reports" From e53e9740daaee8280e8e1c6802b83d643628c207 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Fri, 20 Nov 2026 14:20:15 +0100 Subject: [PATCH 08/14] ci(benchmarks): apply review cleanups Drop the dead datadog.appsec.helper_path ini line (the substitution never resolved and the setting does not exist in the current extension). Restore the CFLAGS stability comment and document the CPU partition. Fix the CPU range in the README, scope the log tarballs to appsec, name the 10% gate threshold, restore the macrobenchmark flaky instructions, and add the analyzer variables to the local-reproduction recipe. Register benchmarks-pr-comment and build-benchmark-ci-images in the CI job inventories. Add the missing trailing newline to bp-runner.fail-on-regression.yml and drop the garbled comment above BASE_CI_IMAGE_SUFFIX. Replace em-dashes per house style. --- .claude/ci/benchmarks.md | 6 ++- .claude/ci/index.md | 3 +- .gitlab/benchmarks.yml | 3 -- .gitlab/benchmarks/README.md | 42 +++++++++++-------- .../bp-runner.fail-on-regression.yml | 2 +- .gitlab/benchmarks/bp-runner.yml | 8 ++-- 6 files changed, 36 insertions(+), 28 deletions(-) diff --git a/.claude/ci/benchmarks.md b/.claude/ci/benchmarks.md index cc7eaf05a6c..1f3d9564669 100644 --- a/.claude/ci/benchmarks.md +++ b/.claude/ci/benchmarks.md @@ -4,7 +4,7 @@ **Source:** - `.gitlab/generate-package.php` — declares `include: .gitlab/benchmarks.yml` and the pipeline stages -- `.gitlab/benchmarks.yml` — all benchmark job definitions; the microbenchmark +- `.gitlab/benchmarks.yml`: all benchmark job definitions; the microbenchmark steps, container and gate configs live in `.gitlab/benchmarks/` (see `.gitlab/benchmarks/README.md`) @@ -13,13 +13,15 @@ | `benchmarks-tracer` | `$MICROBENCHMARKS_CI_IMAGE` (see `.gitlab/benchmarks.yml`; built in-repo from `.gitlab/benchmarks/container/`) | Runs PHP tracer microbenchmarks via the Benchmarking Platform framework; skips automatically if no tracer-relevant files changed | | `benchmarks-appsec` | same | Runs appsec microbenchmarks; produces `candidate.tar.gz` and `baseline.tar.gz` artifacts | | `benchmarks-profiler` | same | Runs profiler microbenchmarks | +| `benchmarks-pr-comment` | `$MICROBENCHMARKS_CI_IMAGE` (see `.gitlab/benchmarks.yml`; built in-repo from `.gitlab/benchmarks/container/`) | Runs `.gitlab/benchmarks/bp-runner.pr-comment.yml`: posts the comparison as a PR comment and uploads the results to the Benchmarking Platform API; needs `benchmarks-tracer` and, optionally, `benchmarks-appsec` and `benchmarks-profiler` (it reports every scenario that ran); allow_failure | +| `build-benchmark-ci-images` | (built in-repo from `.gitlab/benchmarks/container/`) | Manual job that builds the microbenchmark CI image from `.gitlab/benchmarks/container/`; described in `.gitlab/benchmarks/README.md` § How to rebuild the CI Docker image | | `macrobenchmarks: [{PHP_VERSION}]` | `486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:php_laravel-realworld` | Runs a Laravel Realworld application under k6 load at three traffic levels; PHP 7.4 and 8.1 | | `check-big-regressions` | `registry.ddbuild.io/images/benchmarking-platform-tools-ubuntu@sha256:b682acae509fa391ac559705b66df07cac876e4c46641d2457077972a1c0bbb8` | Post-benchmark gate: fails if `benchmarks-tracer` results contain a regression above threshold | | `check-slo-breaches` | (benchmarking-platform-tools template) | Post-macrobenchmark gate: evaluates SLO breaches | | `notify-slo-breaches` | (benchmarking-platform-tools template) | Posts SLO breach notifications to `#guild-dd-php` Slack channel | Runner: `runner:apm-k8s-tweaked-metal` (microbenchmarks); `runner:apm-k8s-same-cpu` -(macrobenchmarks); `arch:amd64` (gate jobs). +(macrobenchmarks); `arch:amd64` (gate and report jobs). **Trigger rules:** - `benchmarks-tracer` — runs on every push; has an early-exit guard: if none of diff --git a/.claude/ci/index.md b/.claude/ci/index.md index ce02cca2822..590837f9391 100644 --- a/.claude/ci/index.md +++ b/.claude/ci/index.md @@ -410,7 +410,8 @@ Dedicated performance hardware — not easily reproducible locally. → **[benchmarks.md](benchmarks.md)** Covers: `benchmarks-tracer`, `benchmarks-appsec`, `benchmarks-profiler`, -`macrobenchmarks [7.4]`, `macrobenchmarks [8.1]` +`benchmarks-pr-comment`, `macrobenchmarks [7.4]`, `macrobenchmarks [8.1]`, +`build-benchmark-ci-images` --- diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index cc004bc495d..84b4c8da934 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -112,9 +112,6 @@ variables: # `.gitlab/benchmarks/container/` (see `.gitlab/benchmarks/README.md`). MICROBENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-php-152770667 # The Dockerfile is located at: .gitlab/benchmarks/container/Dockerfile - # The per-pipeline - # suffix pins each build to a unique tag so a rebuild can't shift what older - # pipelines pulled. BASE_CI_IMAGE_SUFFIX: dd-trace-php-${CI_PIPELINE_ID} BASE_CI_IMAGE_CONTAINER_DIR: .gitlab/benchmarks/container MACROBENCHMARKS_CI_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:php_laravel-realworld diff --git a/.gitlab/benchmarks/README.md b/.gitlab/benchmarks/README.md index 54986304786..f91532959ff 100644 --- a/.gitlab/benchmarks/README.md +++ b/.gitlab/benchmarks/README.md @@ -8,27 +8,27 @@ on every PR. This directory holds everything the microbenchmark jobs need: -- **`container/`** — Dockerfile for the `MICROBENCHMARKS_CI_IMAGE` CI image, +- **`container/`**: Dockerfile for the `MICROBENCHMARKS_CI_IMAGE` CI image, built in-repo via the [`build-ci-images.template.yml`](https://github.com/DataDog/benchmarking-platform-tools/blob/main/images/templates/gitlab/build-ci-images.template.yml) include (see [How to rebuild the CI Docker image](#how-to-rebuild-the-ci-docker-image)). -- **`steps/`** — `update-dd-agent-config.sh`, the config script of the +- **`steps/`**: `update-dd-agent-config.sh`, the config script of the `datadog_agent` step (bp-runner has no `update_dd_agent_config` step type). -- **`bp-runner.yml`** — [bp-runner](https://github.com/DataDog/benchmarking-platform-tools/tree/main/bp-runner) +- **`bp-runner.yml`**: [bp-runner](https://github.com/DataDog/benchmarking-platform-tools/tree/main/bp-runner) experiment definition: captures hardware/software info, starts a local Datadog agent, does the one-time setup (ini appends, mysql and redis start, sysctl), clones the candidate and the baseline and runs `benchmark/runall.sh` on pinned CPUs, converts the results per framework (PHPBench, tea's Google Benchmark, Sirun), and uploads the reports to S3. -- **`bp-runner.pr-comment.yml`** — posts the comparison on the PR and uploads +- **`bp-runner.pr-comment.yml`**: posts the comparison on the PR and uploads the converted results to the Benchmarking Platform API (run by the separate `benchmarks-pr-comment` job). -- **`bp-runner.fail-on-regression.yml`** — gate config used by +- **`bp-runner.fail-on-regression.yml`**: gate config used by `check-big-regressions` to fail the pipeline on regressions above its - threshold. + threshold (10%). The jobs themselves (`benchmarks-tracer`, `benchmarks-appsec`, -`benchmarks-profiler`, `check-big-regressions`) are defined in +`benchmarks-profiler`, `benchmarks-pr-comment`, `check-big-regressions`) are defined in [`.gitlab/benchmarks.yml`](../benchmarks.yml), which runs as a child pipeline of `package-trigger` (the stage list it validates against is generated by `.gitlab/generate-package.php`). @@ -41,15 +41,15 @@ Execution flow on each PR: runs (the baseline is the PR's merge-target branch, at the merge base, resolved by bp-runner's auto lookup). 2. Each run's `benchmark/` suite results are saved as - `reports/$BASELINE_OR_CANDIDATE-.` artifacts, with the logs - tarred as `candidate.tar.gz`/`baseline.tar.gz`. + `reports/$BASELINE_OR_CANDIDATE-.` artifacts; only the AppSec job + also uploads the logs, tarred as `candidate.tar.gz`/`baseline.tar.gz`. 3. The config's analyze steps convert the results per framework (PHPBench, GoogleBenchmark for tea, Sirun) and the S3 teardown archives the reports; `benchmarks-pr-comment` runs `bp-runner.pr-comment.yml` to push the converted results to the Benchmarking Platform API so they land on the project's trend series. 4. `check-big-regressions` gates the pipeline on regressions above the - threshold in `bp-runner.fail-on-regression.yml`, and + threshold of 10% in `bp-runner.fail-on-regression.yml`, and `benchmarks-pr-comment` comments the comparison on the PR. ## How to add a new microbenchmark @@ -57,7 +57,7 @@ Execution flow on each PR: Where a benchmark lives depends on the scenario it belongs to: - **tracer / appsec** (`benchmarks-tracer`, `benchmarks-appsec`): PHPBench - suites in [`tests/Benchmarks/`](../../tests/Benchmarks/) — + suites in [`tests/Benchmarks/`](../../tests/Benchmarks/), with tracer benchmarks in the default groups, AppSec ones under the `frameworks` group (`BENCHMARK_EXTRA="--group=frameworks"`). - **tracer, tea** (`benchmarks-tracer`): C++ Google Benchmark suite in @@ -72,7 +72,7 @@ Where a benchmark lives depends on the scenario it belongs to: 2. Run it locally the same way the job does (see [How to run the suite locally](#how-to-run-the-suite-locally)). 3. Push the branch and let the benchmark job run: new benchmarks are picked - up automatically — the scenarios are discovered from the suites' own + up automatically: the scenarios are discovered from the suites' own result files, not from a list. On the first run the baseline may not contain the new benchmark, so it appears as candidate-only in the comparison. @@ -93,8 +93,10 @@ otherwise. ## How to mark a benchmark as known flaky -Add it to `FLAKY_BENCHMARKS_REGEX` in the `.microbenchmarks` template's -`variables` in [`.gitlab/benchmarks.yml`](../benchmarks.yml). The benchmark +Add it to `FLAKY_BENCHMARKS_REGEX` in the matching template's `variables` in +[`.gitlab/benchmarks.yml`](../benchmarks.yml): the `.microbenchmarks` template +for the microbenchmark jobs, or the `.macrobenchmarks` template for the +macrobenchmarks. The benchmark still runs and reports, but doesn't fail performance quality gates (`check-big-regressions` here, percentage-based; `check-slo-breaches` for the macrobenchmarks, SLO-based). @@ -126,7 +128,7 @@ or updating `sirun`). image from `BASE_CI_IMAGE_CONTAINER_DIR` (`.gitlab/benchmarks/container`) and pushes it as `registry.ddbuild.io/ci/benchmarking-platform:$BASE_CI_IMAGE_SUFFIX` - (`dd-trace-php-` — one unique tag per pipeline, so a rebuild + (`dd-trace-php-`, one unique tag per pipeline, so a rebuild can't shift what older pipelines pulled). 3. Open the pipeline on @@ -162,21 +164,25 @@ Benchmarking Platform wrapper: ``` - profiler: `SCENARIO=profiler ./benchmark/runall.sh` from the repo root (sirun drives `profiling/benches/timeline.json` and - `profiling/benches/exceptions.json` after a natively compiled profiler — + `profiling/benches/exceptions.json` after a natively compiled profiler; see `benchmark/run_with_native_profiler.sh`). To reproduce a full CI run including the baseline comparison, run the job's steps from the repository root with the environment the CI job provides -(`SCENARIO`/`BP_SCENARIO`, `ARTIFACTS_DIR`): +(`SCENARIO`/`BP_SCENARIO`, `ARTIFACTS_DIR`). Also export the analyzer +variables the CI jobs set (`UNCONFIDENCE_THRESHOLD=2.0`, `CI_TYPE=theoretical`, +`MD_REPORT_ONLY_CHANGES=1`); without them the local analysis uses a +significance threshold of 1.0 and prints the unchanged-results table: ```bash export ARTIFACTS_DIR="$(pwd)/reports" +export UNCONFIDENCE_THRESHOLD=2.0 CI_TYPE=theoretical MD_REPORT_ONLY_CHANGES=1 SCENARIO=tracer BP_SCENARIO=tracer bp-runner .gitlab/benchmarks/bp-runner.yml --debug -t ``` Note that `bp-runner.yml` starts a real Datadog agent (the API key comes from AWS SSM in CI, set `DD_API_KEY` yourself locally), needs a GitHub token for -the baseline lookup, and pins the benchmark CPUs (26-47 on the 48-core CI +the baseline lookup, and pins the benchmark CPUs (34-47 on the 48-core CI runners), so a faithful local run needs a comparable machine. ## Other benchmark suites (not in this directory) diff --git a/.gitlab/benchmarks/bp-runner.fail-on-regression.yml b/.gitlab/benchmarks/bp-runner.fail-on-regression.yml index c0d1ae13635..d94451bdc8a 100644 --- a/.gitlab/benchmarks/bp-runner.fail-on-regression.yml +++ b/.gitlab/benchmarks/bp-runner.fail-on-regression.yml @@ -3,4 +3,4 @@ experiments: steps: - name: Regression Check run: fail_on_regression - regression_threshold: 10.0 # percents \ No newline at end of file + regression_threshold: 10.0 # percents diff --git a/.gitlab/benchmarks/bp-runner.yml b/.gitlab/benchmarks/bp-runner.yml index a841c6ce9e1..2d1fd5fb387 100644 --- a/.gitlab/benchmarks/bp-runner.yml +++ b/.gitlab/benchmarks/bp-runner.yml @@ -7,8 +7,11 @@ experiments: env: COMPOSER_ALLOW_SUPERUSER: "1" DD_TRACE_AUTOLOAD_NO_COMPILE: "true" + # Improve stability of benchmarks CFLAGS: "-O2 -falign-functions=64" RUN_WEB_BENCHES_WITH_DDPROF: "1" + # CPU partition on the 48-core runners: 24-25 agent, 26-29 mysql, 30-33 redis, + # 34-47 benchmark process. The setup and run steps span 26-47. setup: - name: datadog-agent run: datadog_agent @@ -32,7 +35,6 @@ experiments: if [ "$BP_SCENARIO" = "appsec" ]; then echo "extension=ddappsec.so" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini echo "datadog.appsec.cli_start_on_rinit=true" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini - echo "datadog.appsec.helper_path=$(PHP_EXTENSION_DIR)/libddappsec-helper.so" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini echo "datadog.appsec.rules=/tmp/recommended.json" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini echo "datadog.appsec.helper_socket_path=/tmp/ddappsec.sock" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini echo "datadog.appsec.helper_lock_path=/tmp/ddappsec.lock" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini @@ -77,8 +79,8 @@ experiments: # base, with baseline resolution left to bp-runner's auto lookup). # runall.sh writes fixed, unprefixed names into $ARTIFACTS_DIR; this # script renames each result to - # $ARTIFACTS_DIR/$BASELINE_OR_CANDIDATE-. — the layout the - # analyze steps below and the fail-on-regression gate glob — gives the + # $ARTIFACTS_DIR/$BASELINE_OR_CANDIDATE-., the layout the + # analyze steps below and the fail-on-regression gate glob, gives the # OPCache and AppSec subjects their distinguishing suffixes, and tars # the run's logs. how_to_run_benchmarks: | From 7c79b50d536876248437f59ee706efbaac54abe5 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Fri, 20 Nov 2026 14:29:14 +0100 Subject: [PATCH 09/14] ci(benchmarks): report each scenario from its own job needs: optional only tolerates a job that is absent from the pipeline; a manual job that is present but unplayed still skips the dependent, so the unified job would never comment on tracer-only PRs. Give each scenario its own reporting job behind a shared template: each needs only its own run job and is manual exactly when that job is. The appsec and profiler configs set the old per-scenario comment headers, and the BP API upload runs per scenario as before the migration. --- .claude/ci/benchmarks.md | 4 +- .claude/ci/index.md | 3 +- .gitlab/benchmarks.yml | 55 ++++++++++++------- .gitlab/benchmarks/README.md | 16 ++++-- .../bp-runner.pr-comment-appsec.yml | 12 ++++ .../bp-runner.pr-comment-profiler.yml | 12 ++++ .gitlab/benchmarks/bp-runner.pr-comment.yml | 1 + 7 files changed, 74 insertions(+), 29 deletions(-) create mode 100644 .gitlab/benchmarks/bp-runner.pr-comment-appsec.yml create mode 100644 .gitlab/benchmarks/bp-runner.pr-comment-profiler.yml diff --git a/.claude/ci/benchmarks.md b/.claude/ci/benchmarks.md index 1f3d9564669..52c20a010df 100644 --- a/.claude/ci/benchmarks.md +++ b/.claude/ci/benchmarks.md @@ -13,7 +13,9 @@ | `benchmarks-tracer` | `$MICROBENCHMARKS_CI_IMAGE` (see `.gitlab/benchmarks.yml`; built in-repo from `.gitlab/benchmarks/container/`) | Runs PHP tracer microbenchmarks via the Benchmarking Platform framework; skips automatically if no tracer-relevant files changed | | `benchmarks-appsec` | same | Runs appsec microbenchmarks; produces `candidate.tar.gz` and `baseline.tar.gz` artifacts | | `benchmarks-profiler` | same | Runs profiler microbenchmarks | -| `benchmarks-pr-comment` | `$MICROBENCHMARKS_CI_IMAGE` (see `.gitlab/benchmarks.yml`; built in-repo from `.gitlab/benchmarks/container/`) | Runs `.gitlab/benchmarks/bp-runner.pr-comment.yml`: posts the comparison as a PR comment and uploads the results to the Benchmarking Platform API; needs `benchmarks-tracer` and, optionally, `benchmarks-appsec` and `benchmarks-profiler` (it reports every scenario that ran); allow_failure | +| `benchmarks-pr-comment` | `$MICROBENCHMARKS_CI_IMAGE` (see `.gitlab/benchmarks.yml`; built in-repo from `.gitlab/benchmarks/container/`) | Runs `.gitlab/benchmarks/bp-runner.pr-comment.yml`: posts the tracer comparison as a PR comment and uploads the results to the Benchmarking Platform API; needs `benchmarks-tracer`; allow_failure | +| `benchmarks-pr-comment-appsec` | same | Same flow for AppSec, with its own comment header; needs `benchmarks-appsec` | +| `benchmarks-pr-comment-profiler` | same | Same flow for the profiler, with its own comment header; needs `benchmarks-profiler` | | `build-benchmark-ci-images` | (built in-repo from `.gitlab/benchmarks/container/`) | Manual job that builds the microbenchmark CI image from `.gitlab/benchmarks/container/`; described in `.gitlab/benchmarks/README.md` § How to rebuild the CI Docker image | | `macrobenchmarks: [{PHP_VERSION}]` | `486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:php_laravel-realworld` | Runs a Laravel Realworld application under k6 load at three traffic levels; PHP 7.4 and 8.1 | | `check-big-regressions` | `registry.ddbuild.io/images/benchmarking-platform-tools-ubuntu@sha256:b682acae509fa391ac559705b66df07cac876e4c46641d2457077972a1c0bbb8` | Post-benchmark gate: fails if `benchmarks-tracer` results contain a regression above threshold | diff --git a/.claude/ci/index.md b/.claude/ci/index.md index 590837f9391..5ffdcc97d43 100644 --- a/.claude/ci/index.md +++ b/.claude/ci/index.md @@ -410,7 +410,8 @@ Dedicated performance hardware — not easily reproducible locally. → **[benchmarks.md](benchmarks.md)** Covers: `benchmarks-tracer`, `benchmarks-appsec`, `benchmarks-profiler`, -`benchmarks-pr-comment`, `macrobenchmarks [7.4]`, `macrobenchmarks [8.1]`, +`benchmarks-pr-comment`, `benchmarks-pr-comment-appsec`, +`benchmarks-pr-comment-profiler`, `macrobenchmarks [7.4]`, `macrobenchmarks [8.1]`, `build-benchmark-ci-images` --- diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index 84b4c8da934..71f8591c642 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -303,32 +303,16 @@ benchmarks-appsec: # Posts the comparison and uploads results. allow_failure preserves the old || : # semantics, and a separate job avoids the parallel-teardown race with the S3 # upload. -benchmarks-pr-comment: +# One reporting job per scenario: appsec and profiler benchmarks are manual, +# tracer is not, and a need on an unplayed manual job makes GitLab skip the +# dependent. +.benchmarks-report: stage: benchmarks-report - # Optional needs: appsec and profiler are manual on most pipelines, and a - # non-optional need on a manual job that did not run makes GitLab skip this - # job. Optional needs collect their artifacts when they ran and proceed - # without them otherwise. - needs: - - benchmarks-tracer - - job: benchmarks-appsec - optional: true - - job: benchmarks-profiler - optional: true allow_failure: true when: on_success tags: ["arch:amd64"] image: $MICROBENCHMARKS_CI_IMAGE timeout: 30m - rules: *benchmarks-tracer-rules - variables: - # See https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/7223313012/Flaky+Benchmarks+Monitoring for more details. - FLAKY_BENCHMARKS_REGEX: "" - # Analyzer settings the PR comment's comparison output depends on. - UNCONFIDENCE_THRESHOLD: "2.0" - DISABLE_NHST: "1" - CI_TYPE: "theoretical" - MD_REPORT_ONLY_CHANGES: "1" 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/" @@ -340,13 +324,42 @@ benchmarks-pr-comment: echo "ERROR: Reports directory exists but is empty - benchmarks job had issues" exit 1 fi - - bp-runner "${CI_PROJECT_DIR}/.gitlab/benchmarks/bp-runner.pr-comment.yml" --debug + - bp-runner "${CI_PROJECT_DIR}/.gitlab/benchmarks/$BP_RUNNER_PR_COMMENT_CONFIG" --debug artifacts: name: "reports" when: always paths: - reports/ expire_in: 3 months + variables: + # See https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/7223313012/Flaky+Benchmarks+Monitoring for more details. + FLAKY_BENCHMARKS_REGEX: "" + # Analyzer settings the PR comment's comparison output depends on. + UNCONFIDENCE_THRESHOLD: "2.0" + DISABLE_NHST: "1" + CI_TYPE: "theoretical" + MD_REPORT_ONLY_CHANGES: "1" + +benchmarks-pr-comment: + extends: .benchmarks-report + rules: *benchmarks-tracer-rules + needs: [benchmarks-tracer] + variables: + BP_RUNNER_PR_COMMENT_CONFIG: "bp-runner.pr-comment.yml" + +benchmarks-pr-comment-appsec: + extends: .benchmarks-report + rules: *benchmarks-appsec-rules + needs: [benchmarks-appsec] + variables: + BP_RUNNER_PR_COMMENT_CONFIG: "bp-runner.pr-comment-appsec.yml" + +benchmarks-pr-comment-profiler: + extends: .benchmarks-report + rules: *benchmarks-profiler-rules + needs: [benchmarks-profiler] + variables: + BP_RUNNER_PR_COMMENT_CONFIG: "bp-runner.pr-comment-profiler.yml" # Kafka and RabbitMQ produce/consume throughput with Data Streams Monitoring # off and on, against real brokers and agent; fails if DSM adds more than 3% diff --git a/.gitlab/benchmarks/README.md b/.gitlab/benchmarks/README.md index f91532959ff..a6d8ca2ba85 100644 --- a/.gitlab/benchmarks/README.md +++ b/.gitlab/benchmarks/README.md @@ -22,13 +22,17 @@ This directory holds everything the microbenchmark jobs need: Benchmark, Sirun), and uploads the reports to S3. - **`bp-runner.pr-comment.yml`**: posts the comparison on the PR and uploads the converted results to the Benchmarking Platform API (run by the separate - `benchmarks-pr-comment` job). + `benchmarks-pr-comment` job; `bp-runner.pr-comment-appsec.yml` and + `bp-runner.pr-comment-profiler.yml` are the same flow with the AppSec and + profiler comment headers, run by `benchmarks-pr-comment-appsec` and + `benchmarks-pr-comment-profiler`). - **`bp-runner.fail-on-regression.yml`**: gate config used by `check-big-regressions` to fail the pipeline on regressions above its threshold (10%). The jobs themselves (`benchmarks-tracer`, `benchmarks-appsec`, -`benchmarks-profiler`, `benchmarks-pr-comment`, `check-big-regressions`) are defined in +`benchmarks-profiler`, `benchmarks-pr-comment`, `benchmarks-pr-comment-appsec`, +`benchmarks-pr-comment-profiler`, `check-big-regressions`) are defined in [`.gitlab/benchmarks.yml`](../benchmarks.yml), which runs as a child pipeline of `package-trigger` (the stage list it validates against is generated by `.gitlab/generate-package.php`). @@ -45,12 +49,12 @@ Execution flow on each PR: also uploads the logs, tarred as `candidate.tar.gz`/`baseline.tar.gz`. 3. The config's analyze steps convert the results per framework (PHPBench, GoogleBenchmark for tea, Sirun) and the S3 teardown archives the reports; - `benchmarks-pr-comment` runs `bp-runner.pr-comment.yml` to push the - converted results to the Benchmarking Platform API so they land on the - project's trend series. + `benchmarks-pr-comment*` jobs run their `bp-runner.pr-comment*.yml` to + push the converted results to the Benchmarking Platform API so they land on + the project's trend series. 4. `check-big-regressions` gates the pipeline on regressions above the threshold of 10% in `bp-runner.fail-on-regression.yml`, and - `benchmarks-pr-comment` comments the comparison on the PR. + `benchmarks-pr-comment*` comments the comparison on the PR. ## How to add a new microbenchmark diff --git a/.gitlab/benchmarks/bp-runner.pr-comment-appsec.yml b/.gitlab/benchmarks/bp-runner.pr-comment-appsec.yml new file mode 100644 index 00000000000..0a2cb9cb632 --- /dev/null +++ b/.gitlab/benchmarks/bp-runner.pr-comment-appsec.yml @@ -0,0 +1,12 @@ +experiments: + - name: Post PR comment + steps: + - name: Post PR comment + run: post_pr_comment + header: Benchmarks [ appsec ] + +global_teardown: + - name: Upload to BP API + run: upload_to_bp_api + retries_on_failure: 3 + project: dd-trace-php diff --git a/.gitlab/benchmarks/bp-runner.pr-comment-profiler.yml b/.gitlab/benchmarks/bp-runner.pr-comment-profiler.yml new file mode 100644 index 00000000000..c525ddeacad --- /dev/null +++ b/.gitlab/benchmarks/bp-runner.pr-comment-profiler.yml @@ -0,0 +1,12 @@ +experiments: + - name: Post PR comment + steps: + - name: Post PR comment + run: post_pr_comment + header: Benchmarks [ profiler ] + +global_teardown: + - name: Upload to BP API + run: upload_to_bp_api + retries_on_failure: 3 + project: dd-trace-php diff --git a/.gitlab/benchmarks/bp-runner.pr-comment.yml b/.gitlab/benchmarks/bp-runner.pr-comment.yml index 46f5c2f38f9..a6c3124c4ce 100644 --- a/.gitlab/benchmarks/bp-runner.pr-comment.yml +++ b/.gitlab/benchmarks/bp-runner.pr-comment.yml @@ -3,6 +3,7 @@ experiments: steps: - name: Post PR comment run: post_pr_comment + header: Benchmarks [ tracer ] global_teardown: - name: Upload to BP API From 4a8838639cafbc2c41c08c0fab21bbdaf8e88580 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Fri, 20 Nov 2026 14:55:31 +0100 Subject: [PATCH 10/14] ci(benchmarks): run the tracer bench when the benchmark CI changes The skip guard watches only tracer source paths, so a PR that changes the benchmark harness itself skips the bench that would validate it (this PR's head skipped: the diff is .gitlab-only). Watch .gitlab/benchmarks.yml and .gitlab/benchmarks/ too. Makefile stays out: it is the repo's main build file, and watching it would put a 90-minute metal run on every build PR. --- .gitlab/benchmarks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index 71f8591c642..2d00d186813 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -227,7 +227,7 @@ workflow: echo "Checking if tracer-related files changed..." git fetch origin master:master 2>/dev/null || true CHANGED_FILES=$(git diff --name-only HEAD master 2>/dev/null || echo "") - if ! echo "$CHANGED_FILES" | grep -q -E "^(ext/|src/|components/|components-rs/|zend_abstract_interface/|tests/Benchmarks/|benchmark/|tea/)"; then + if ! echo "$CHANGED_FILES" | grep -q -E "^(ext/|src/|components/|components-rs/|zend_abstract_interface/|tests/Benchmarks/|benchmark/|tea/|\.gitlab/benchmarks\.yml|\.gitlab/benchmarks/)"; then echo "No tracer-related file changes detected - skipping benchmark execution" echo "Reports directory created but empty (no benchmarks needed)" > "${ARTIFACTS_DIR}/skip-reason.txt" exit 0 From d69c8de8ecd9f27ade97e179d8b1ede54dc092a1 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Fri, 20 Nov 2026 16:17:41 +0100 Subject: [PATCH 11/14] ci(benchmarks): schedule the appsec and profiler report jobs automatically The report jobs inherited when: manual from the scenario rules on PRs without appsec or profiling changes. A manually played benchmark then got no comment and no BP API upload without a second manual play, where the old flow reported from inside the same job. Give the report jobs a plain on_success rule: they run automatically once the needed benchmark job succeeds, and are skipped quietly when it never runs. --- .gitlab/benchmarks.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index 00027a99c8b..81c5931294f 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -346,14 +346,16 @@ benchmarks-pr-comment: benchmarks-pr-comment-appsec: extends: .benchmarks-report - rules: *benchmarks-appsec-rules + rules: + - when: on_success needs: [benchmarks-appsec] variables: BP_RUNNER_PR_COMMENT_CONFIG: "bp-runner.pr-comment-appsec.yml" benchmarks-pr-comment-profiler: extends: .benchmarks-report - rules: *benchmarks-profiler-rules + rules: + - when: on_success needs: [benchmarks-profiler] variables: BP_RUNNER_PR_COMMENT_CONFIG: "bp-runner.pr-comment-profiler.yml" From e231abf16932c248d7626a9fd2d2b80be42547d6 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Fri, 20 Nov 2026 16:19:42 +0100 Subject: [PATCH 12/14] docs(benchmarks): say the benchmark CI triggers the tracer bench The paragraph said CI-plumbing changes never need a benchmark run, which the skip-guard change inverted. Document that benchmark CI changes run benchmarks-tracer like tracer changes, that appsec and profiler stay manual unless their sources change, and that playing the benchmark job is enough because its report job follows automatically. --- .gitlab/benchmarks/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab/benchmarks/README.md b/.gitlab/benchmarks/README.md index a6d8ca2ba85..7bf8f0c2567 100644 --- a/.gitlab/benchmarks/README.md +++ b/.gitlab/benchmarks/README.md @@ -90,10 +90,10 @@ expect a one-run mismatch on renames. If the benchmark becomes unstable while you iterate, see [How to mark a benchmark as known flaky](#how-to-mark-a-benchmark-as-known-flaky). -Changes that only affect CI plumbing (this directory, `.gitlab/benchmarks.yml`) -don't need a benchmark run: the benchmark jobs only auto-run when -tracer-relevant paths change, and can be triggered manually from the pipeline -otherwise. +Changes to the benchmark CI (this directory, `.gitlab/benchmarks.yml`) run +`benchmarks-tracer` like tracer changes do. AppSec and profiler stay manual +unless their sources change: play the benchmark job to exercise a CI change +there; its `benchmarks-pr-comment-*` job follows automatically. ## How to mark a benchmark as known flaky From 9c6d1bfb0aea029bacc279b8416e73928fb3036e Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Fri, 20 Nov 2026 16:37:46 +0100 Subject: [PATCH 13/14] ci(benchmarks): drop dead analyzer vars, set SIGNIFICANT_IMPACT_THRESHOLD to 5% DISABLE_NHST has no reader in bp-analyzer (it reads ENABLE_NHST, default off) and CI_TYPE: theoretical is the default, so both are dead config carried over from the old platform script. UNCONFIDENCE_THRESHOLD survives only as the deprecated fallback for SIGNIFICANT_IMPACT_THRESHOLD. MD_REPORT_ONLY_CHANGES stays: its default is off and the comment output depends on it. --- .gitlab/benchmarks.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index 81c5931294f..64ada4461ee 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -256,9 +256,7 @@ workflow: # See https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/7223313012/Flaky+Benchmarks+Monitoring for more details. # Analyzer settings. Every bp-runner step inherits the CI process environment, # so the settings live here instead of the config. - UNCONFIDENCE_THRESHOLD: "2.0" - DISABLE_NHST: "1" - CI_TYPE: "theoretical" + SIGNIFICANT_IMPACT_THRESHOLD: "5.0" MD_REPORT_ONLY_CHANGES: "1" FLAKY_BENCHMARKS_REGEX: "" @@ -332,9 +330,7 @@ benchmarks-appsec: # See https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/7223313012/Flaky+Benchmarks+Monitoring for more details. FLAKY_BENCHMARKS_REGEX: "" # Analyzer settings the PR comment's comparison output depends on. - UNCONFIDENCE_THRESHOLD: "2.0" - DISABLE_NHST: "1" - CI_TYPE: "theoretical" + SIGNIFICANT_IMPACT_THRESHOLD: "5.0" MD_REPORT_ONLY_CHANGES: "1" benchmarks-pr-comment: From 89143775d985ffb4c01876b512df0008d3d83363 Mon Sep 17 00:00:00 2001 From: Augusto de Oliveira Date: Fri, 20 Nov 2026 17:03:05 +0100 Subject: [PATCH 14/14] ci(benchmarks): drop the obsolete AppSec ini block from the setup Under the combined extension there is no ddappsec.so, the helper socket and lock settings were deleted with the sidecar move, and the rules, cli_start_on_rinit, and log lines are already exported by benchmark/runall.sh, whose environment reaches the measured php-cgi servers. cli_start_on_rinit also only gates the cli and frankenphp SAPIs, so it never affected the cgi-fcgi servers. extension=ddtrace.so stays: it is the only loader of the combined extension into those servers. --- .gitlab/benchmarks/bp-runner.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.gitlab/benchmarks/bp-runner.yml b/.gitlab/benchmarks/bp-runner.yml index 2d1fd5fb387..16f0e25ad1b 100644 --- a/.gitlab/benchmarks/bp-runner.yml +++ b/.gitlab/benchmarks/bp-runner.yml @@ -32,15 +32,6 @@ experiments: if [ "$BP_SCENARIO" = "tracer" ] || [ "$BP_SCENARIO" = "appsec" ]; then echo "extension=ddtrace.so" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini - if [ "$BP_SCENARIO" = "appsec" ]; then - echo "extension=ddappsec.so" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini - echo "datadog.appsec.cli_start_on_rinit=true" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini - echo "datadog.appsec.rules=/tmp/recommended.json" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini - echo "datadog.appsec.helper_socket_path=/tmp/ddappsec.sock" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini - echo "datadog.appsec.helper_lock_path=/tmp/ddappsec.lock" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini - echo "datadog.appsec.log_file=/tmp/logs/appsec.log" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini - echo "datadog.appsec.helper_log_file=/tmp/logs/helper.log" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini - fi taskset -c 26-29 service mysql start taskset -c 30-33 redis-server --daemonize yes fi