diff --git a/.claude/ci/benchmarks.md b/.claude/ci/benchmarks.md index 0670f0a720..cc7eaf05a6 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 ad24ce9f71..0000000000 --- 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 d28b58d061..0dc677909a 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,7 +215,7 @@ workflow: tags: ["runner:apm-k8s-tweaked-metal"] needs: [] image: - name: $BASE_CI_IMAGE + name: $MICROBENCHMARKS_CI_IMAGE timeout: 90m script: - export ARTIFACTS_DIR="$(pwd)/reports" && (mkdir "${ARTIFACTS_DIR}" || :) @@ -219,15 +233,15 @@ 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 + - export PATH="$PATH:${CI_PROJECT_DIR}/.gitlab/benchmarks/steps" + - capture-hardware-software-info.sh # Keep submodules at the selected candidate and baseline revisions. - >- 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 + - analyze-results.sh + - "upload-results-to-s3.sh || :" + - "post-pr-comment.sh || :" artifacts: name: "reports" paths: @@ -336,12 +350,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 0000000000..4394117ad2 --- /dev/null +++ b/.gitlab/benchmarks/README.md @@ -0,0 +1,186 @@ +# 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/`** — the run, analyze, upload and PR-comment scripts the jobs call + (copied from the former `dd-trace-php` branch of + [benchmarking-platform](https://github.com/DataDog/benchmarking-platform)). +- **`bp-runner.yml`** — [bp-runner](https://github.com/DataDog/benchmarking-platform-tools/tree/main/bp-runner) + experiment definition: starts a local Datadog agent, then runs + `steps/run-benchmarks.sh` on pinned CPUs. +- **`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`), + collects hardware/software info, and runs + `bp-runner .gitlab/benchmarks/bp-runner.yml`. +2. `run-benchmarks.sh` clones the candidate commit and the baseline + (the PR's merge-target branch, at the merge base), runs each checkout's + `benchmark/` suite, and saves the results as `reports/` artifacts. +3. `analyze-results.sh` converts the results with the benchmark analyzer, + `upload-results-to-s3.sh` archives them to S3, and + `upload-results-to-benchmarking-api.sh` pushes them to the Benchmarking + Platform API so results 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 `post-pr-comment.sh` + 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`, `UPSTREAM_BRANCH`, `UPSTREAM_COMMIT_SHA`, `UPSTREAM_PROJECT_NAME`, +`ARTIFACTS_DIR`): + +```bash +export ARTIFACTS_DIR="$(pwd)/reports" +export PATH="$PATH:$PWD/.gitlab/benchmarks/steps" +capture-hardware-software-info.sh +SCENARIO=tracer BP_SCENARIO=tracer bp-runner .gitlab/benchmarks/bp-runner.yml --debug -t +analyze-results.sh +``` + +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) 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 0000000000..c0d1ae1363 --- /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.yml b/.gitlab/benchmarks/bp-runner.yml new file mode 100644 index 0000000000..6701c94948 --- /dev/null +++ b/.gitlab/benchmarks/bp-runner.yml @@ -0,0 +1,14 @@ +experiments: + - name: run-microbenchmarks + setup: + - name: datadog-agent + run: datadog_agent + cpus: 24-25 + config_sh: .gitlab/benchmarks/steps/update-dd-agent-config.sh + + steps: + - name: benchmarks + cpus: 26-47 + run: shell + script: export SCENARIO=$BP_SCENARIO && .gitlab/benchmarks/steps/run-benchmarks.sh + diff --git a/.gitlab/benchmarks/container/Dockerfile b/.gitlab/benchmarks/container/Dockerfile new file mode 100644 index 0000000000..4ee33dd0ac --- /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/analyze-results.sh b/.gitlab/benchmarks/steps/analyze-results.sh new file mode 100755 index 0000000000..5f1d8c18ec --- /dev/null +++ b/.gitlab/benchmarks/steps/analyze-results.sh @@ -0,0 +1,279 @@ +#!/usr/bin/env bash + +set -ex + +# Benchmark analyzer config + +source $(dirname "$0")/config-benchmark-analyzer.sh + +CPU_MODEL=$(cat "$ARTIFACTS_DIR/lscpu.txt" | grep -Eo 'Model name: .*' | sed 's/Model name://' | awk '{$1=$1;print}') +CI_JOB_DATE=$(date +%s) + +if [ -z "$CPU_MODEL" ]; then + echo "FAIL! Failed to extract CPU_MODEL from lscpu.txt" + exit 1 +fi + +KERNEL_VERSION=$(uname -a || echo "Unknown") + +# -- Analyze candidate branch results + +CANDIDATE_BRANCH=$UPSTREAM_BRANCH +CANDIDATE_SRC="/app/candidate/" + +# Get commit SHA for candidate branch +cd "$CANDIDATE_SRC" +CANDIDATE_COMMIT_SHA=$(git rev-parse HEAD) +CANDIDATE_COMMIT_DATE=$(git show -s --format=%ct $CANDIDATE_COMMIT_SHA) + +if [ "$SCENARIO" = "profiler" ]; then + benchmark_analyzer convert \ + --extra-params="{\ + \"baseline_or_candidate\":\"candidate\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"kernel_version\":\"$KERNEL_VERSION\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$CANDIDATE_COMMIT_SHA\", \ + \"git_commit_date\":\"$CANDIDATE_COMMIT_DATE\", \ + \"git_branch\":\"$CANDIDATE_BRANCH\"\ + }" \ + --framework=Sirun \ + --outpath="$ARTIFACTS_DIR/candidate_timeline_memory.converted.json" \ + "$ARTIFACTS_DIR/candidate/sirun_timeline.ndjson" + + benchmark_analyzer convert \ + --extra-params="{\ + \"baseline_or_candidate\":\"candidate\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"kernel_version\":\"$KERNEL_VERSION\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$CANDIDATE_COMMIT_SHA\", \ + \"git_commit_date\":\"$CANDIDATE_COMMIT_DATE\", \ + \"git_branch\":\"$CANDIDATE_BRANCH\"\ + }" \ + --framework=Sirun \ + --outpath="$ARTIFACTS_DIR/candidate_exceptions.converted.json" \ + "$ARTIFACTS_DIR/candidate/sirun_exceptions.ndjson" + + benchmark_analyzer analyze \ + --format=md \ + --outpath="$ARTIFACTS_DIR/candidate-analysis.md" \ + "$ARTIFACTS_DIR/candidate_timeline_memory.converted.json" \ + "$ARTIFACTS_DIR/candidate_exceptions.converted.json" +elif [ "$SCENARIO" = "tracer" ]; then + # Analyze Tracing Benchmarks + benchmark_analyzer convert \ + --extra-params="{\ + \"baseline_or_candidate\":\"candidate\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"kernel_version\":\"$KERNEL_VERSION\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$CANDIDATE_COMMIT_SHA\", \ + \"git_commit_date\":\"$CANDIDATE_COMMIT_DATE\", \ + \"git_branch\":\"$CANDIDATE_BRANCH\"\ + }" \ + --framework=PHPBench \ + --outpath="$ARTIFACTS_DIR/candidate_${SCENARIO}_bench.converted.json" \ + "$ARTIFACTS_DIR/candidate/${SCENARIO}-bench-results.csv" + + benchmark_analyzer convert \ + --extra-params="{\ + \"baseline_or_candidate\":\"candidate\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"kernel_version\":\"$KERNEL_VERSION\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$CANDIDATE_COMMIT_SHA\", \ + \"git_commit_date\":\"$CANDIDATE_COMMIT_DATE\", \ + \"git_branch\":\"$CANDIDATE_BRANCH\"\ + }" \ + --framework=PHPBench \ + --outpath="$ARTIFACTS_DIR/candidate_${SCENARIO}_bench_opcache.converted.json" \ + "$ARTIFACTS_DIR/candidate/${SCENARIO}-bench-results-opcache.csv" + + benchmark_analyzer convert \ + --extra-params="{\ + \"baseline_or_candidate\":\"candidate\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"kernel_version\":\"$KERNEL_VERSION\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$CANDIDATE_COMMIT_SHA\", \ + \"git_commit_date\":\"$CANDIDATE_COMMIT_DATE\", \ + \"git_branch\":\"$CANDIDATE_BRANCH\"\ + }" \ + --framework=GoogleBenchmark \ + --outpath="$ARTIFACTS_DIR/candidate_${SCENARIO}_tea_bench.converted.json" \ + "$ARTIFACTS_DIR/candidate/${SCENARIO}-tea-bench-results.json" +elif [ "$SCENARIO" = "appsec" ]; then + benchmark_analyzer convert \ + --extra-params="{\ + \"baseline_or_candidate\":\"candidate\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$CANDIDATE_COMMIT_SHA\", \ + \"git_commit_date\":\"$CANDIDATE_COMMIT_DATE\", \ + \"git_branch\":\"$CANDIDATE_BRANCH\"\ + }" \ + --framework=PHPBench \ + --outpath="$ARTIFACTS_DIR/candidate_${SCENARIO}_bench.converted.json" \ + "$ARTIFACTS_DIR/candidate/${SCENARIO}-bench-results.csv" +fi + +# -- Analyze baseline branch results + +BASELINE_SRC="/app/baseline/" +if [ -d $BASELINE_SRC ]; then + BASELINE_BRANCH=$(github-find-merge-into-branch --for-repo="$UPSTREAM_PROJECT_NAME" --for-pr="$UPSTREAM_BRANCH" || :) + + # Get commit SHA for baseline branch + cd "$BASELINE_SRC" + BASELINE_COMMIT_SHA=$(git rev-parse HEAD) + BASELINE_COMMIT_DATE=$(git show -s --format=%ct $BASELINE_COMMIT_SHA) + + if [ "$SCENARIO" = "profiler" ]; then + # Analyze Profiling Benchmarks + benchmark_analyzer convert \ + --extra-params="{\ + \"baseline_or_candidate\":\"baseline\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"kernel_version\":\"$KERNEL_VERSION\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$BASELINE_COMMIT_SHA\", \ + \"git_commit_date\":\"$BASELINE_COMMIT_DATE\", \ + \"git_branch\":\"$BASELINE_BRANCH\"\ + }" \ + --framework=Sirun \ + --outpath="$ARTIFACTS_DIR/baseline_timeline_memory.converted.json" \ + "$ARTIFACTS_DIR/baseline/sirun_timeline.ndjson" + + benchmark_analyzer convert \ + --extra-params="{\ + \"baseline_or_candidate\":\"baseline\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"kernel_version\":\"$KERNEL_VERSION\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$BASELINE_COMMIT_SHA\", \ + \"git_commit_date\":\"$BASELINE_COMMIT_DATE\", \ + \"git_branch\":\"$BASELINE_BRANCH\"\ + }" \ + --framework=Sirun \ + --outpath="$ARTIFACTS_DIR/baseline_exceptions.converted.json" \ + "$ARTIFACTS_DIR/baseline/sirun_exceptions.ndjson" + + benchmark_analyzer analyze \ + --format=md \ + --outpath="$ARTIFACTS_DIR/baseline-analysis.md" \ + "$ARTIFACTS_DIR/baseline_timeline_memory.converted.json" \ + "$ARTIFACTS_DIR/baseline_exceptions.converted.json" + elif [ "$SCENARIO" = "tracer" ]; then + # Analyze Tracing Benchmarks + benchmark_analyzer convert \ + --extra-params="{\ + \"baseline_or_candidate\":\"baseline\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"kernel_version\":\"$KERNEL_VERSION\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$BASELINE_COMMIT_SHA\", \ + \"git_commit_date\":\"$BASELINE_COMMIT_DATE\", \ + \"git_branch\":\"$BASELINE_BRANCH\"\ + }" \ + --framework=PHPBench \ + --outpath="$ARTIFACTS_DIR/baseline_${SCENARIO}_bench.converted.json" \ + "$ARTIFACTS_DIR/baseline/${SCENARIO}-bench-results.csv" + + benchmark_analyzer convert \ + --extra-params="{\ + \"baseline_or_candidate\":\"baseline\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"kernel_version\":\"$KERNEL_VERSION\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$BASELINE_COMMIT_SHA\", \ + \"git_commit_date\":\"$BASELINE_COMMIT_DATE\", \ + \"git_branch\":\"$BASELINE_BRANCH\"\ + }" \ + --framework=PHPBench \ + --outpath="$ARTIFACTS_DIR/baseline_${SCENARIO}_bench_opcache.converted.json" \ + "$ARTIFACTS_DIR/baseline/${SCENARIO}-bench-results-opcache.csv" + + benchmark_analyzer convert \ + --extra-params="{\ + \"baseline_or_candidate\":\"baseline\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"kernel_version\":\"$KERNEL_VERSION\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$BASELINE_COMMIT_SHA\", \ + \"git_commit_date\":\"$BASELINE_COMMIT_DATE\", \ + \"git_branch\":\"$BASELINE_BRANCH\"\ + }" \ + --framework=GoogleBenchmark \ + --outpath="$ARTIFACTS_DIR/baseline_${SCENARIO}_tea_bench.converted.json" \ + "$ARTIFACTS_DIR/baseline/${SCENARIO}-tea-bench-results.json" + elif [ "$SCENARIO" = "appsec" ]; then + benchmark_analyzer convert \ + --extra-params="{\ + \"baseline_or_candidate\":\"baseline\", \ + \"cpu_model\":\"$CPU_MODEL\", \ + \"ci_job_date\":\"$CI_JOB_DATE\", \ + \"ci_job_id\":\"$CI_JOB_ID\", \ + \"ci_pipeline_id\":\"$CI_PIPELINE_ID\", \ + \"git_commit_sha\":\"$BASELINE_COMMIT_SHA\", \ + \"git_commit_date\":\"$BASELINE_COMMIT_DATE\", \ + \"git_branch\":\"$BASELINE_BRANCH\"\ + }" \ + --framework=PHPBench \ + --outpath="$ARTIFACTS_DIR/baseline_${SCENARIO}_bench.converted.json" \ + "$ARTIFACTS_DIR/baseline/${SCENARIO}-bench-results.csv" + fi +fi + +# -- Compare results between baseline and candidate branches + +if [ -d $BASELINE_SRC ]; then + if [ "$SCENARIO" = "profiler" ]; then + benchmark_analyzer compare pairwise \ + --baseline='{"baseline_or_candidate":"baseline"}' \ + --candidate='{"baseline_or_candidate":"candidate"}' \ + --format=md-nodejs \ + --outpath="$ARTIFACTS_DIR/comparison-baseline-vs-candidate.md" \ + "$ARTIFACTS_DIR/baseline_timeline_memory.converted.json" "$ARTIFACTS_DIR/candidate_timeline_memory.converted.json" \ + "$ARTIFACTS_DIR/baseline_exceptions.converted.json" "$ARTIFACTS_DIR/candidate_exceptions.converted.json" + elif [ "$SCENARIO" = "tracer" ]; then + benchmark_analyzer compare pairwise \ + --baseline='{"baseline_or_candidate":"baseline"}' \ + --candidate='{"baseline_or_candidate":"candidate"}' \ + --format=md-nodejs \ + --outpath="$ARTIFACTS_DIR/comparison-baseline-vs-candidate.md" \ + "$ARTIFACTS_DIR/baseline_${SCENARIO}_bench.converted.json" "$ARTIFACTS_DIR/candidate_${SCENARIO}_bench.converted.json" \ + "$ARTIFACTS_DIR/baseline_${SCENARIO}_bench_opcache.converted.json" "$ARTIFACTS_DIR/candidate_${SCENARIO}_bench_opcache.converted.json" \ + "$ARTIFACTS_DIR/baseline_${SCENARIO}_tea_bench.converted.json" "$ARTIFACTS_DIR/candidate_${SCENARIO}_tea_bench.converted.json" + elif [ "$SCENARIO" = "appsec" ]; then + benchmark_analyzer compare pairwise \ + --baseline='{"baseline_or_candidate":"baseline"}' \ + --candidate='{"baseline_or_candidate":"candidate"}' \ + --format=md-nodejs \ + --outpath="$ARTIFACTS_DIR/comparison-baseline-vs-candidate.md" \ + "$ARTIFACTS_DIR/baseline_${SCENARIO}_bench.converted.json" "$ARTIFACTS_DIR/candidate_${SCENARIO}_bench.converted.json" + fi +fi + diff --git a/.gitlab/benchmarks/steps/capture-hardware-software-info.sh b/.gitlab/benchmarks/steps/capture-hardware-software-info.sh new file mode 100755 index 0000000000..87e846e876 --- /dev/null +++ b/.gitlab/benchmarks/steps/capture-hardware-software-info.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +cd "${ARTIFACTS_DIR}" + +# Collect software information + +(which top && top -b -n 1 > top.txt) || : +(which uname && uname -a > uname.txt) || : +(which ldconfig && ldconfig -v > ldconfig.txt) || : +(which sysctl && sysctl -a > sysctl.txt) || : +(which php && php -v > php.txt) || : + +# Collect hardware information + +(which lscpu && lscpu -e > lscpu-e.txt) || : +(which lscpu && lscpu > lscpu.txt) || : +(which hwinfo && hwinfo --short > hwinfo-short.txt) || : +(which hwinfo && hwinfo > hwinfo-full.txt) || : +(which cpupower && cpupower frequency-info > cpupower-frequency-info.txt) || : +(which turbostat && turbostat -n 1 > turbostat.txt) || : diff --git a/.gitlab/benchmarks/steps/config-benchmark-analyzer.sh b/.gitlab/benchmarks/steps/config-benchmark-analyzer.sh new file mode 100755 index 0000000000..0d3a3a7e20 --- /dev/null +++ b/.gitlab/benchmarks/steps/config-benchmark-analyzer.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +export UNCONFIDENCE_THRESHOLD=2.0 +export DISABLE_NHST=1 +export CI_TYPE=theoretical +export MD_REPORT_ONLY_CHANGES=1 diff --git a/.gitlab/benchmarks/steps/post-pr-comment.sh b/.gitlab/benchmarks/steps/post-pr-comment.sh new file mode 100755 index 0000000000..5b8d96222b --- /dev/null +++ b/.gitlab/benchmarks/steps/post-pr-comment.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# Temporarily enable uploading from inside pr commenter script, till dd-trace-py repo has an update +$(dirname "$0")/upload-results-to-benchmarking-api.sh || : + +cat "$ARTIFACTS_DIR/comparison-baseline-vs-candidate.md" | pr-commenter --for-repo="$UPSTREAM_PROJECT_NAME" --for-pr="$UPSTREAM_BRANCH" --header="Benchmarks [ $SCENARIO ]" --on-duplicate=replace diff --git a/.gitlab/benchmarks/steps/run-benchmarks.sh b/.gitlab/benchmarks/steps/run-benchmarks.sh new file mode 100755 index 0000000000..1afc524925 --- /dev/null +++ b/.gitlab/benchmarks/steps/run-benchmarks.sh @@ -0,0 +1,137 @@ +#!/usr/bin/env bash + +set -ex + +# -- Candidate release + +CANDIDATE_SRC="/app/candidate/" +CANDIDATE_BRANCH=$UPSTREAM_BRANCH +CANDIDATE_COMMIT_SHA=$UPSTREAM_COMMIT_SHA + +GITLAB_ARTIFACTS_PATH="/go/src/github.com/DataDog/apm-reliability/dd-trace-php/" + +# Clone your candidate release +git clone --recurse-submodules --branch "$CANDIDATE_BRANCH" https://github.com/DataDog/dd-trace-php/ "$CANDIDATE_SRC" && \ + cd "$CANDIDATE_SRC" && \ + git checkout "$CANDIDATE_COMMIT_SHA" && \ + git submodule update --init --recursive + +if [ "$SCENARIO" = "tracer" ] || [ "$SCENARIO" = "appsec" ]; then + echo "extension=ddtrace.so" >> /etc/php/8.2/cgi/conf.d/ddtrace.ini + if [ "$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 + +# Allow composer to run as root +export COMPOSER_ALLOW_SUPERUSER=1 + +# Allow Autoloading (See Datadog/dd-trace-php:tests/bootstrap.php) +export DD_TRACE_AUTOLOAD_NO_COMPILE=true +unset CI + +# Improve stability of benchmarks +export CFLAGS="-O2 -falign-functions=64" + +# 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 + +# Don't filter ddprof benches away +export RUN_WEB_BENCHES_WITH_DDPROF=1 + +save_run_results () { + TYPE=$1 + OUTPUT_DIR="$ARTIFACTS_DIR/$TYPE" + + # Save results to artifacts directory + mkdir -p "$OUTPUT_DIR" + if [ "$SCENARIO" = "profiler" ]; then + cp $ARTIFACTS_DIR/sirun_timeline.ndjson "$OUTPUT_DIR" + cp $ARTIFACTS_DIR/sirun_exceptions.ndjson "$OUTPUT_DIR" + elif [ "$SCENARIO" = "tracer" ]; then + # For the OPCache CSV results, we replace the value of the subject (third column by default) with the value of the + # subject followed by "-opcache", to differentiate it from the non-opcache results + 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/tracer-bench-results-opcache.csv && \ + + cp $ARTIFACTS_DIR/tracer-bench-results.csv "$OUTPUT_DIR" + cp $ARTIFACTS_DIR/tracer-bench-results-opcache.csv "$OUTPUT_DIR" + cp $ARTIFACTS_DIR/tracer-tea-bench-results.json "$OUTPUT_DIR" + elif [ "$SCENARIO" = "appsec" ]; then + # For the OPCache CSV results, we replace the value of the subject (third column by default) with the value of the + # subject followed by "-opcache", to differentiate it from the non-opcache results + 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 "$OUTPUT_DIR/appsec-bench-results.csv" + + awk -F ',' -v OFS=',' 'NR == 1 { print } NR > 1 { $3 = $3 "-appsec-opcache"; print }' $ARTIFACTS_DIR/appsec-bench-results-opcache.csv > $ARTIFACTS_DIR/appsec-bench-results-opcache.tmp && \ + mv $ARTIFACTS_DIR/appsec-bench-results-opcache.tmp "$OUTPUT_DIR/appsec-bench-results-opcache.csv" + + cat $ARTIFACTS_DIR/appsec-tea-bench-results.json | jq '( .benchmarks[] | select(.name) | .name ) |= "AppSec_\(.)"' > "$OUTPUT_DIR/appsec-tea-bench-results.json" + fi + + #Save all logs as artifacts + tar -zcvf $GITLAB_ARTIFACTS_PATH/$TYPE.tar.gz /tmp/logs + + # Clean up artifacts directory before next run + (rm "$ARTIFACTS_DIR/*.ndjson" || :) && (rm "$ARTIFACTS_DIR/*.csv" || :) && (rm "$ARTIFACTS_DIR/*.json" || :) && (rm "$ARTIFACTS_DIR/*.tmp" || :) && (rm -rf "/tmp/logs" || :) +} + +# Run benchmarks for candidate release +cd "$CANDIDATE_SRC/benchmark/" +rm -rf /tmp/logs/ +mkdir -p /tmp/logs +taskset -c 34-47 ./runall.sh +save_run_results "candidate" + +# Run benchmarks for baseline release +BASELINE_SRC="/app/baseline/" +BASELINE_BRANCH=$(github-find-merge-into-branch --for-repo="$UPSTREAM_PROJECT_NAME" --for-pr="$UPSTREAM_BRANCH" || :) + +if [ ! -z "$BASELINE_BRANCH" ]; then + echo $BASELINE_BRANCH > $ARTIFACTS_DIR/baseline_branch.txt + + cd "$CANDIDATE_SRC" + BASELINE_COMMIT_SHA=$(git merge-base origin/$BASELINE_BRANCH origin/$CANDIDATE_BRANCH) + + # Clone your baseline release + git clone --recurse-submodules --branch "$BASELINE_BRANCH" https://github.com/DataDog/dd-trace-php/ "$BASELINE_SRC" && \ + cd "$BASELINE_SRC" && \ + git checkout "$BASELINE_COMMIT_SHA" && \ + git submodule update --init --recursive + + # Run benchmarks for baseline release + cd "$BASELINE_SRC/benchmark/" + mkdir -p /tmp/logs + taskset -c 34-47 ./runall.sh + save_run_results "baseline" +fi + + + +# Teardown MySQL +if [ "$SCENARIO" = "tracer" ] || [ "$SCENARIO" = "appsec" ]; then + service mysql stop +fi 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 0000000000..880e1c579c --- /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/benchmarks/steps/upload-results-to-benchmarking-api.sh b/.gitlab/benchmarks/steps/upload-results-to-benchmarking-api.sh new file mode 100755 index 0000000000..a2ce87d6a4 --- /dev/null +++ b/.gitlab/benchmarks/steps/upload-results-to-benchmarking-api.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +PROJECT=dd-trace-php + +function upload_results_to_api() { + set -e + + PREFIX=$1 + BASELINE_PREFIX=$2 + CONVERTED_JSON="$PREFIX.converted.json" + + if [ ! -f "$CONVERTED_JSON" ]; then + echo "FAIL! ${CONVERTED_JSON} was not found, uploading failed!" + return + fi + + if [ -f "${BASELINE_PREFIX}.converted.json" ]; then + BASELINE_COMMIT_SHA=$(cat "${BASELINE_PREFIX}.converted.json" | jq -c '.benchmarks[0].parameters.git_commit_sha' | tr -d '''"' ) + BASELINE_CI_PIPELINE_ID=$(cat "${BASELINE_PREFIX}.converted.json" | jq -c '.benchmarks[0].parameters.ci_pipeline_id' | tr -d '''"' ) + fi + + STATUSCODE=$(curl -s --output /dev/stderr --write-out "%{http_code}" --form file=@"$CONVERTED_JSON" "https://benchmarking-service.us1.prod.dog/benchmarks/upload/$PROJECT?baseline_commit_sha=$BASELINE_COMMIT_SHA&baseline_ci_pipeline_id=$BASELINE_CI_PIPELINE_ID") + if test $STATUSCODE -ne 200; then + exit 1 + fi + + echo "SUCCESS! Uploaded $CONVERTED_JSON to Benchmarking Platform service!" +} + +cd "$ARTIFACTS_DIR" +for fcandidate in candidate_*.converted.json; do + [ -e "$fcandidate" ] || continue + + fcandidate=$(echo "$fcandidate" | sed "s#$ARTIFACTS_DIR/##g" | sed "s#\\.converted\\.json##g") + fbaseline=$(echo "$fcandidate" | sed "s#candidate#baseline#g") + + if [[ -f "$fbaseline.converted.json" ]]; then + upload_results_to_api $fbaseline "" + upload_results_to_api $fcandidate $fbaseline + else + upload_results_to_api $fcandidate "" + fi +done + +for fcandidate in candidate_*.converted.json; do + [ -e "$fcandidate" ] || continue + + CANDIDATE_COMMIT_SHA=$(cat "$fcandidate" | jq -c '.benchmarks[0].parameters.git_commit_sha' | tr -d '''"' ) + CANDIDATE_CI_PIPELINE_ID=$(cat "$fcandidate" | jq -c '.benchmarks[0].parameters.ci_pipeline_id' | tr -d '''"' ) + + echo "" + echo "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + echo "" + echo "" + echo "See the results in BP UI: https://benchmarking.us1.prod.dog/benchmarks?benchmarkGroupPipelineId=$CANDIDATE_CI_PIPELINE_ID&benchmarkGroupSha=$CANDIDATE_COMMIT_SHA" + echo "" + echo "" + echo "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + echo "" + + break +done diff --git a/.gitlab/benchmarks/steps/upload-results-to-s3.sh b/.gitlab/benchmarks/steps/upload-results-to-s3.sh new file mode 100755 index 0000000000..f5e0a37dd5 --- /dev/null +++ b/.gitlab/benchmarks/steps/upload-results-to-s3.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +PROJECT="${UPSTREAM_PROJECT_NAME:-$CI_PROJECT_NAME}" +BRANCH="${UPSTREAM_BRANCH:-$CI_COMMIT_REF_NAME}" + +# BP_EXTERNAL_S3_URL overrides the default destination prefix (must stay within +# relenv-benchmarking-data) so an external orchestrator can collect results +# under a prefix it controls. +S3_URL="${BP_EXTERNAL_S3_URL:-s3://relenv-benchmarking-data/${PROJECT}/${BRANCH}/${CI_JOB_ID}/}" +[[ "$S3_URL" == s3://relenv-benchmarking-data/* ]] || { echo "BP_EXTERNAL_S3_URL must stay within relenv-benchmarking-data" >&2; exit 1; } + +aws s3 cp --recursive --acl bucket-owner-full-control "${ARTIFACTS_DIR}/" "$S3_URL"