throttle-kit 2.1.1

Rate limiting for Rust — GCRA (Generic Cell Rate Algorithm) with pluggable
Documentation
name: CI
on:
  push:
    branches: [main, master]
  pull_request:

jobs:
  quality:
    uses: WyattAu/engineering-standards/.github/workflows/rust-kit.yml@main
    with:
      tier: a
      all-features: true
      loom: false
      wasm: false
      miri: false
      # criterion wall-clock benches: human-readable trend, non-gating.
      # The pass/fail gate is the `perf-gate` job below (iai-callgrind,
      # deterministic instruction counts).
      bench-regression: true

  # Deterministic perf gate: iai-callgrind instruction counts on the
  # RateLimiter::check hot path (benches/iai_hot_path.rs).
  #
  # Baseline workflow: every push to main re-saves the `main` baseline and
  # caches it; PRs compare against it with --fail-fast (first regression
  # fails the job). Baseline updates are INTENTIONAL — after merging a
  # deliberate perf change, the next main push refreshes the reference.
  # Live Redis GCRA suite (tests/redis_gcra_live.rs): the Lua-script
  # decision loop needs a real server — GitHub provides one as a service;
  # locally, `docker run -p 6379:6379 redis:7` and run with `--ignored`.
  integration:
    name: Integration (live redis GCRA)
    runs-on: ubuntu-latest
    services:
      redis:
        image: redis:7
        ports:
          - 6379:6379
        options: >-
          --health-cmd "redis-cli ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      # The redis service covers the four quota tests; the fail-open test
      # spins up its own throwaway container (docker preinstalled).
      - name: live GCRA suite (fixture-gated)
        run: cargo test --features redis --test redis_gcra_live -- --ignored --nocapture
        env:
          THROTTLE_KIT_REDIS_URL: redis://127.0.0.1:6379/

  perf-gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - name: Install valgrind + iai-callgrind runner
        # iai-callgrind shells out to valgrind (callgrind tool); recent
        # ubuntu-latest runner images (202609xx) no longer ship it
        # preinstalled, which failed the bench with "cannot find binary
        # path: 'valgrind'".
        run: |
          sudo apt-get update && sudo apt-get install -y valgrind
          cargo install iai-callgrind-runner --locked
      - name: Restore main baseline
        if: github.event_name == 'pull_request'
        uses: actions/cache/restore@v4
        with:
          path: target/iai
          key: iai-baseline-main-notused-${{ github.run_id }}
          restore-keys: iai-baseline-main-
      - name: Save baseline (push to main)
        if: github.event_name == 'push' && github.ref == 'refs/heads/main'
        run: cargo bench --bench iai_hot_path -- --save-baseline=main
      - name: Regression gate (PRs)
        if: github.event_name == 'pull_request'
        run: cargo bench --bench iai_hot_path -- --baseline=main --fail-fast
      - name: Save baseline cache (push to main)
        if: github.event_name == 'push' && github.ref == 'refs/heads/main'
        uses: actions/cache/save@v4
        with:
          path: target/iai
          key: iai-baseline-main-${{ github.run_id }}