Skip to main content

PR-PerfGuard

CLI и GitHub Action для автоматического регрессионного нагрузочного тестирования в Pull Requests.

PR-PerfGuard поднимает ваш сервис прямо в CI, прогревает его, прогоняет асинхронный нагрузочный сценарий (RPS, p50 / p95 / p99 latency, error rate, peak RSS memory), сравнивает результаты с baseline-отчётом из main и публикует в PR наглядный Markdown-отчёт (sticky comment) со статусом PASS / FAIL по заданным порогам.


Пример отчёта в Pull Request

🛡️ PR-PerfGuard Report — ❌ REGRESSION DETECTED

  • Target: http://127.0.0.1:8000/api/items
  • Load: 25 concurrent workers × 15.0s (18420 requests)
Metric Baseline (main) PR Delta Threshold Status
p50 Latency 12.40 ms 13.10 ms +5.65% info ✅
p95 Latency 24.80 ms 32.50 ms +31.05% <= +15.0% ❌
p99 Latency 41.20 ms 48.00 ms +16.50% <= +25.0% ✅
Throughput (RPS) 1280.00 req/s 1228.00 req/s -4.06% drop <= 10.0% ✅
Error Rate 0.00% 0.00% +0.00 pp <= 1.0% ✅
Peak RSS Memory 84.50 MB 88.20 MB +4.38% <= +20.0% ✅

Установка и быстрый старт

Из GitHub (без публикации в PyPI):

pip install git+https://github.com/b3mug1/pr-perfguard.git

Или локально для разработки:

pip install -e ".[dev]"

1. Создайте конфиг perfguard.yml

perfguard init

2. Снимите baseline (например, на ветке main)

perfguard run --config perfguard.yml --out .perfguard/baseline.json

3. Проверьте изменения в PR

perfguard check --config perfguard.yml --baseline .perfguard/baseline.json --out .perfguard/current.json

Команда вернёт exit code 1, если хотя бы одна метрика превысила допустимый порог регрессии.

Также можно запускать без perfguard.yml — напрямую через флаги:

perfguard run --url http://127.0.0.1:8000/health --concurrency 20 --duration 10 --repeats 3 --out baseline.json
perfguard compare baseline.json current.json

Продвинутая конфигурация (perfguard.yml)

  • Мульти-эндпоинтовые сценарии (load.endpoints): задавайте несколько маршрутов с весами (weight), разными HTTP-методами, заголовками, телом запроса и ожидаемыми статус-кодами (expected_statuses, по умолчанию 200..399).
  • Переменные окружения: в url, headers и body поддерживается подстановка ${VAR_NAME} из os.environ.
  • Фиксированный RPS (load.target_rps / --target-rps): позволяет задать целевую интенсивность нагрузки (req/s) вместо максимального насыщения — удобно для точного сравнения latency между main и PR при одинаковом трафике.
  • Защита от шума CI:
    • load.repeats (или --repeats N) — прогоняет N замеров после прогрева и берёт медиану по каждой метрике.
    • thresholds.min_p95_delta_ms / min_p99_delta_ms — минимальный абсолютный порог прироста задержки в миллисекундах, чтобы микроскопические колебания не давали ложный FAIL.
  • Строгая валидация: опечатки в ключах и неверные значения в perfguard.yml сразу приводят к понятной ошибке при старте.

Полный пример смотрите в examples/perfguard.yml.


Использование как GitHub Action

name: Performance Guard
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  baseline:
    if: github.event_name == 'push'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: pip install git+https://github.com/b3mug1/pr-perfguard.git
      - run: perfguard run --config perfguard.yml --out .perfguard/baseline.json
      - uses: actions/cache/save@v4
        with:
          path: .perfguard/baseline.json
          key: perfguard-baseline-${{ github.sha }}

  perfguard:
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - uses: actions/checkout@v4

      - uses: actions/cache/restore@v4
        with:
          path: .perfguard/baseline.json
          key: perfguard-baseline-${{ github.event.pull_request.base.sha }}
          restore-keys: perfguard-baseline-

      - id: guard
        uses: b3mug1/pr-perfguard@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          config: perfguard.yml
          baseline: .perfguard/baseline.json
          pr-number: ${{ github.event.pull_request.number }}

Action также выставляет outputs passed ("true" / "false") и report-path (путь к сгенерированному Markdown-отчёту).


Разработка и тесты

ruff check src tests
pytest -v

Metadata

Release files for pr-perfguard 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pr-perfguard 0.2.0
File Size Uploaded Provenance Actions
pr_perfguard-0.2.0.tar.gz 22.6 kB With provenance Details for pr_perfguard-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pr-perfguard 0.2.0
File Interpreter ABI Platform Actions
pr_perfguard-0.2.0-py3-none-any.whl Python 3 none any Details for pr_perfguard-0.2.0-py3-none-any.whl

Total release size: 39.7 kB

Release files / pr_perfguard-0.2.0.tar.gz

Download URL pr_perfguard-0.2.0.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f46cb2d511358f7a7b5395707a6a10b8cec515803451eeb1e662bbd86b03e4bd
BLAKE2b-256 checksum
How to use checksums
1fd3da8b76f52bc8ed641d2bc0162fd6ba7f2c61a1dbe1bf8596294e23a5e61c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / pr_perfguard-0.2.0-py3-none-any.whl

Download URL pr_perfguard-0.2.0-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ffe413f0413a564aaa32a3266c49cd844a191283f1f7cdf007109b12f8f2b35
BLAKE2b-256 checksum
How to use checksums
8eea34abe01ec54737e3fe9a98c875932278cf7db14bafe4f4951414685ea5d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for pr-perfguard 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pr_perfguard-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page