diff --git a/.claude/ci/benchmarks.md b/.claude/ci/benchmarks.md index 24d3b74abc..32325eb5c1 100644 --- a/.claude/ci/benchmarks.md +++ b/.claude/ci/benchmarks.md @@ -13,13 +13,16 @@ | `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, one `TRACER_PART` (phpbench, phpbench-opcache, tea) and, for the phpbench parts, one `PHPBENCH_SHARD` (1, 2) per matrix job; 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 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` | +| `benchmarks-pr-comment` | `$BENCHMARKING_PLATFORM_TOOLS_IMAGE` (see `.gitlab/benchmarks.yml`) | Posts the tracer comparison as a PR comment (bp-runner config generated inline; no checkout); needs `benchmarks-tracer`; allow_failure | +| `benchmarks-upload-bp-api` | same | Uploads the tracer results to the Benchmarking Platform API, in parallel with the comment; needs `benchmarks-tracer`; allow_failure | +| `benchmarks-pr-comment-appsec` | same | Posts the AppSec comparison as a PR comment (bp-runner config generated inline; no checkout); needs `benchmarks-appsec`; allow_failure | +| `benchmarks-upload-bp-api-appsec` | same | Uploads the AppSec results to the Benchmarking Platform API, in parallel with the comment; needs `benchmarks-appsec`; allow_failure | +| `benchmarks-pr-comment-profiler` | same | Posts the profiler comparison as a PR comment (bp-runner config generated inline; no checkout); needs `benchmarks-profiler`; allow_failure | +| `benchmarks-upload-bp-api-profiler` | same | Uploads the profiler results to the Benchmarking Platform API, in parallel with the comment; needs `benchmarks-profiler`; 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 | | `build-llvm-bolt-align-image` | (built in-repo from `.gitlab/benchmarks/container/llvm-bolt-align/`) | Manual job that builds the static `llvm-bolt-align` tool image copied into the microbenchmark CI image; described in `.gitlab/benchmarks/README.md` § Rebuilding the `llvm-bolt-align` 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, or if any part's candidate results (or baseline results, when there is a baseline branch) are missing | +| `check-big-regressions` | `$BENCHMARKING_PLATFORM_TOOLS_IMAGE` | Post-benchmark gate: fails if `benchmarks-tracer` results contain a regression above threshold, or if any part's candidate results (or baseline results, when there is a baseline branch) are missing | | `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 | diff --git a/.claude/ci/index.md b/.claude/ci/index.md index 5ffdcc97d4..1ebf03fd62 100644 --- a/.claude/ci/index.md +++ b/.claude/ci/index.md @@ -411,7 +411,9 @@ Dedicated performance hardware — not easily reproducible locally. → **[benchmarks.md](benchmarks.md)** Covers: `benchmarks-tracer`, `benchmarks-appsec`, `benchmarks-profiler`, `benchmarks-pr-comment`, `benchmarks-pr-comment-appsec`, -`benchmarks-pr-comment-profiler`, `macrobenchmarks [7.4]`, `macrobenchmarks [8.1]`, +`benchmarks-pr-comment-profiler`, `benchmarks-upload-bp-api`, +`benchmarks-upload-bp-api-appsec`, `benchmarks-upload-bp-api-profiler`, +`macrobenchmarks [7.4]`, `macrobenchmarks [8.1]`, `build-benchmark-ci-images` --- diff --git a/.gitlab/benchmarks.yml b/.gitlab/benchmarks.yml index d717a1bf7d..a65f7a6366 100644 --- a/.gitlab/benchmarks.yml +++ b/.gitlab/benchmarks.yml @@ -112,6 +112,9 @@ variables: # `.gitlab/benchmarks/container/` (see `.gitlab/benchmarks/README.md`). # Built here: https://gitlab.ddbuild.io/DataDog/apm-reliability/dd-trace-php/-/jobs/2300686392 MICROBENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-php-156499868 + # Benchmarking Platform tools image for the jobs that only read reports/. + # Keep in sync with the FROM of .gitlab/benchmarks/container/Dockerfile. + BENCHMARKING_PLATFORM_TOOLS_IMAGE: registry.ddbuild.io/images/benchmarking-platform-tools-ubuntu@sha256:dbdd7f39672099fca20799a44b38e472a029376c98115b449debe68fb8f38856 # The Dockerfile is located at: .gitlab/benchmarks/container/Dockerfile BASE_CI_IMAGE_SUFFIX: dd-trace-php-${CI_PIPELINE_ID} BASE_CI_IMAGE_CONTAINER_DIR: .gitlab/benchmarks/container @@ -320,22 +323,28 @@ benchmarks-appsec: variables: SCENARIO: "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. -# 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-rules: &benchmarks-report-rules + - when: on_success + +# Reporting jobs: a PR comment plus a parallel Benchmarking Platform API +# upload. allow_failure preserves the old || : semantics. +# One pair 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 allow_failure: true when: on_success tags: ["arch:amd64"] - image: $MICROBENCHMARKS_CI_IMAGE + image: $BENCHMARKING_PLATFORM_TOOLS_IMAGE timeout: 30m + variables: + GIT_STRATEGY: none + # See https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/7223313012/Flaky+Benchmarks+Monitoring for more details. + FLAKY_BENCHMARKS_REGEX: "" + +.benchmarks-report-guard: 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" @@ -344,42 +353,94 @@ benchmarks-appsec: 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_CONFIG" --debug + +.benchmarks-report-pr-comment: + extends: .benchmarks-report + variables: + # Analyzer settings the PR comment's comparison output depends on. + SIGNIFICANT_IMPACT_THRESHOLD: "5.0" + MD_REPORT_ONLY_CHANGES: "1" + script: + - !reference [.benchmarks-report-guard, script] + # pr-commenter identifies its comment by this header. + - | + cat > /tmp/bp-runner.pr-comment.yml < /tmp/bp-runner.upload-bp-api.yml </dev/null 2>&1; then echo "Benchmarks were skipped (no relevant file changes) - regression check not needed" diff --git a/.gitlab/benchmarks/README.md b/.gitlab/benchmarks/README.md index a756185006..e14eb7bc61 100644 --- a/.gitlab/benchmarks/README.md +++ b/.gitlab/benchmarks/README.md @@ -23,19 +23,16 @@ This directory holds everything the microbenchmark jobs need: 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.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 reporting jobs' bp-runner configs are generated inline in +`.gitlab/benchmarks.yml`, since those jobs run without a checkout. + The jobs themselves (`benchmarks-tracer`, `benchmarks-appsec`, -`benchmarks-profiler`, `benchmarks-pr-comment`, `benchmarks-pr-comment-appsec`, -`benchmarks-pr-comment-profiler`, `check-big-regressions`) are defined in +`benchmarks-profiler`, `benchmarks-pr-comment*`, `benchmarks-upload-bp-api*`, +`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`). @@ -61,15 +58,17 @@ 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*` 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` and `benchmarks-pr-comment` merge the five - tracer jobs' `reports/`. The gate fails if any part's candidate (or, when - there is a baseline branch, baseline) `.converted.json` is missing, or on + the `benchmarks-upload-bp-api*` jobs push the converted results to the + Benchmarking Platform API so they land on the project's trend series. +4. `check-big-regressions`, `benchmarks-pr-comment` and + `benchmarks-upload-bp-api` merge the five tracer jobs' `reports/`. The + gate fails if any part's candidate (or, when there is a baseline branch, + baseline) `.converted.json` is missing, or 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. The reporting + jobs only read `reports/`, so they skip the checkout and run on + `BENCHMARKING_PLATFORM_TOOLS_IMAGE`. ## Binary layout processing @@ -158,7 +157,8 @@ you iterate, see 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. +there; its `benchmarks-pr-comment-*` and `benchmarks-upload-bp-api-*` jobs +follow automatically. ## How to mark a benchmark as known flaky @@ -186,7 +186,7 @@ Open a ticket to fix or remove it. See 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`). +updating `sirun`, or bumping the tools base digest). 1. Edit the relevant file(s) under `.gitlab/benchmarks/container/`. Push the branch and open a PR. @@ -213,6 +213,12 @@ or updating `sirun`). MICROBENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-php- ``` + The container builds `FROM` the digest pinned in + `BENCHMARKING_PLATFORM_TOOLS_IMAGE` (see `.gitlab/benchmarks.yml`), so a + rebuild can't silently pick up a newer tools base: to bump the tools, repin + the digest in both places together. This keeps the reporting jobs reading + the results with the same tools that wrote them. + 5. Push the update. The microbenchmarks now run against the rebuilt image. Verify a green benchmark pipeline before merging. diff --git a/.gitlab/benchmarks/bp-runner.pr-comment-appsec.yml b/.gitlab/benchmarks/bp-runner.pr-comment-appsec.yml deleted file mode 100644 index 0a2cb9cb63..0000000000 --- a/.gitlab/benchmarks/bp-runner.pr-comment-appsec.yml +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index c525ddeaca..0000000000 --- a/.gitlab/benchmarks/bp-runner.pr-comment-profiler.yml +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index a6c3124c4c..0000000000 --- a/.gitlab/benchmarks/bp-runner.pr-comment.yml +++ /dev/null @@ -1,12 +0,0 @@ -experiments: - - name: Post PR comment - steps: - - name: Post PR comment - run: post_pr_comment - header: Benchmarks [ tracer ] - -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/container/Dockerfile b/.gitlab/benchmarks/container/Dockerfile index 20df4d5585..7779d89fa4 100644 --- a/.gitlab/benchmarks/container/Dockerfile +++ b/.gitlab/benchmarks/container/Dockerfile @@ -2,7 +2,9 @@ # the build-llvm-bolt-align-image job from container/llvm-bolt-align/. FROM registry.ddbuild.io/ci/benchmarking-platform:llvm-bolt-align-156483907@sha256:800c006534c5182a29fef46d6f963398606485194b924c7d5636fd06d155d7fb AS bolt-align -FROM registry.ddbuild.io/images/benchmarking-platform-tools-ubuntu:latest +# Pinned by digest; keep in sync with BENCHMARKING_PLATFORM_TOOLS_IMAGE in +# .gitlab/benchmarks.yml (see README § How to rebuild the CI Docker image). +FROM registry.ddbuild.io/images/benchmarking-platform-tools-ubuntu@sha256:dbdd7f39672099fca20799a44b38e472a029376c98115b449debe68fb8f38856 ARG CI_JOB_TOKEN ARG RUST_VERSION=1.91.1