Skip to content

Production baseline#152

Merged
Tuntii merged 7 commits intomainfrom
Production-baseline
Mar 8, 2026
Merged

Production baseline#152
Tuntii merged 7 commits intomainfrom
Production-baseline

Conversation

@Tuntii
Copy link
Owner

@Tuntii Tuntii commented Mar 8, 2026

Description

This pull request introduces several important improvements to RustAPI's documentation, environment setup, and feature exports. Notably, it clarifies performance benchmarking methodology, adds standard health probe endpoints, and expands public exports for session management, OAuth2, jobs, and replay features. These changes make the framework easier to use in production and clarify how performance claims are maintained.

Documentation and Benchmarking Updates:

  • Clarified that current benchmark methodology and canonical performance claims are maintained in docs/PERFORMANCE_BENCHMARKS.md, with historical numbers preserved as snapshots in release notes and referenced from README.md, CHANGELOG.md, and RELEASES.md. [1] [2] [3] [4]
  • Updated feature comparison tables and documentation to reference benchmark methodology instead of static numbers. [1] [2]

Production and Health Probe Features:

  • Added documentation and code examples for enabling standard health probe endpoints (/health, /ready, /live) via .health_endpoints() and HealthCheckBuilder, as well as a single-call production baseline preset with production_defaults(). [1] [2]
  • Linked new guides for recommended production baseline and checklist.

Replay and Incident Workflow Enhancements:

  • Improved documentation for request/response replay, including admin token usage, CLI changes, and linking to a full incident workflow recipe.

Environment Setup:

  • Added a .env file with placeholder environment variables for local development and documentation examples.

Public API Expansion:

  • Expanded public exports in api/public/rustapi-rs.all-features.txt and api/public/rustapi-rs.default.txt to include session management, OAuth2, jobs, replay, and streaming multipart features, making them available via prelude and extras modules. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16]

CI Workflow Improvements:

  • Updated the benchmark CI workflow to run a performance snapshot example and upload results alongside standard benchmarks.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test addition or update
  • CI/CD changes
  • Other (please describe):

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • If api/public/* snapshots changed, this PR has breaking or feature label

Tuntii added 3 commits March 8, 2026 20:00
Introduce built-in health endpoints and a production baseline preset, plus a synthetic in-process performance snapshot and CI wiring. Changes include: add HealthEndpointConfig, HealthResponse and health helper handlers; RustApi methods to enable health_endpoints(), with_health_check(), and production_defaults()/production_defaults_with_config(); automatically register /health, /ready and /live when configured; tests for health endpoints; a new perf_snapshot example and CI step to run and upload its output; README, CHANGELOG and RELEASES updates to document production defaults and benchmark guidance; new .env for local examples; API exports extended (oauth2/session/job/session stores and helpers); new session module and multiple cookbook/docs/recipes additions; and Cargo.lock updates for new dependencies. Overall this adds production probe ergonomics and a reproducible perf snapshot to the project.
Add public exports for the jobs API and SSE helper and refresh example docs and task list.

- Export sse_from_iter from core and prelude in api/public/rustapi-rs.{all-features,default}.txt
- Add extras::jobs exports (EnqueueOptions, InMemoryBackend, Job, JobBackend, JobContext, JobError, JobQueue, JobRequest) and expose them in the prelude/all-features file
- Update crates/rustapi-rs/examples/README.md: reorder/clarify examples, add endpoint samples for full_crud_api and inline example commands
- Update tasks.md: mark full_crud_api, streaming_api, and jobs_api examples as completed
Introduce observability and benchmarking workflows and CLI ergonomics: add new `bench` and `observability` commands, surface observability assets, and wire a benchmark runner. Expand the `doctor` command to scan workspace signals (health, shutdown, tracing, rate-limit, body limits, etc.), emit structured checks/warnings/failures, and support a --strict mode.

Add project presets and template wiring: introduce ProjectPreset (prod-api, ai-api, realtime-api), recommended feature bundles, CLI --preset support for `cargo rustapi new`, and related tests. Enable the `replay` feature by default for the cargo CLI and export replay, streaming multipart, and RateLimitStrategy types in the public API files.

Library tweaks: expose RateLimitStrategy and extend rate-limit internals to support multiple strategies; clarify multipart usage (drop/consume previous field before next). Update docs/README examples and CLI README entries, add tests for new commands, and update .gitignore to ignore markdown files.
Copilot AI review requested due to automatic review settings March 8, 2026 18:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR establishes a more production-oriented baseline for RustAPI by adding built-in health probes and a one-call production_defaults() preset, expanding rustapi-rs facade exports (sessions/OAuth2/jobs/replay/streaming multipart), and updating documentation + CLI workflows around benchmarking, observability, and replay.

Changes:

  • Added built-in health endpoints (/health, /ready, /live) and a production_defaults() preset + tests.
  • Expanded facade exports and added new examples/recipes for sessions, OAuth2, jobs, replay workflow, streaming APIs, and migrations.
  • Introduced new cargo-rustapi commands (bench, observability) and updated benchmark CI to upload a perf snapshot output.

Reviewed changes

Copilot reviewed 60 out of 63 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tasks.md Task tracking placeholder (present in PR metadata).
docs/cookbook/src/reference/macro_attributes.md New macro attribute reference page.
docs/cookbook/src/reference/README.md Adds reference section intro + link to macro attribute reference.
docs/cookbook/src/recipes/session_auth.md New session-auth recipe using facade exports.
docs/cookbook/src/recipes/replay.md Updates replay docs into a workflow guide (now mixed-language).
docs/cookbook/src/recipes/oidc_oauth2_production.md New production OAuth/OIDC guidance page.
docs/cookbook/src/recipes/observability.md New observability baseline recipe referencing production defaults + layers.
docs/cookbook/src/recipes/oauth2_client.md Updates OAuth2 client recipe to use facade exports + sessions.
docs/cookbook/src/recipes/middleware_debugging.md New middleware debugging guide (layer order, checklist).
docs/cookbook/src/recipes/graceful_shutdown.md Expands shutdown guidance, adds drain/readiness example.
docs/cookbook/src/recipes/error_handling.md New error-handling recipe documenting ApiError patterns and wire format.
docs/cookbook/src/recipes/deployment.md Adds probe recommendations + Kubernetes snippet + minimal production bootstrap.
docs/cookbook/src/recipes/db_integration.md Expands DB guidance (SQLx vs Diesel vs SeaORM, pooling, migrations).
docs/cookbook/src/recipes/custom_extractors.md New custom extractor patterns for parts vs body consumption.
docs/cookbook/src/recipes/axum_migration.md New Axum→RustAPI migration guide.
docs/cookbook/src/recipes/actix_migration.md New Actix-web→RustAPI migration guide.
docs/cookbook/src/recipes/README.md Adds new recipe links (sessions/oauth/replay/observability/migrations/etc.).
docs/cookbook/src/learning/curriculum.md Updates curriculum link to new error-handling recipe.
docs/cookbook/src/concepts/performance.md Replaces static perf numbers with policy + benchmark doc pointers.
docs/cookbook/src/SUMMARY.md Adds new reference/recipe pages to mdbook summary.
docs/README.md Adds quick links to benchmark policy + production baseline/checklist + replay recipe.
docs/PERFORMANCE_BENCHMARKS.md Adds benchmark policy + a “latest validated snapshot” section.
docs/GETTING_STARTED.md Documents new health endpoints + production_defaults() usage.
crates/rustapi-rs/src/lib.rs Expands core/prelude/extras re-exports (health, sessions, oauth2, jobs, replay, streaming multipart, sse_from_iter, etc.).
crates/rustapi-rs/examples/streaming_api.rs New SSE streaming example using sse_from_iter.
crates/rustapi-rs/examples/jobs_api.rs New jobs example gated on jobs feature.
crates/rustapi-rs/examples/full_crud_api.rs New full CRUD example.
crates/rustapi-rs/examples/auth_api.rs New session-auth example gated on session feature.
crates/rustapi-rs/examples/README.md New examples index for facade crate.
crates/rustapi-rs/Cargo.toml Adds rustapi-jobs + futures-util deps; introduces extras session/oauth/jobs features.
crates/rustapi-extras/src/rate_limit/mod.rs Adds new rate limit strategies (fixed/sliding/token-bucket) + tests and exports.
crates/rustapi-extras/src/oauth2/tokens.rs Adds PkceVerifier::new(...) to rebuild from stored verifier; adjusts generate.
crates/rustapi-extras/src/lib.rs Re-exports session module/types + rate limit strategy.
crates/rustapi-extras/Cargo.toml Adds redis dependency + session/session-redis features; updates full feature set.
crates/rustapi-core/tests/production_defaults.rs New integration tests for production defaults preset + probe wiring.
crates/rustapi-core/tests/health_endpoints.rs New integration tests for health endpoints and status codes.
crates/rustapi-core/src/multipart.rs Adds streaming multipart extractor + field type + tests; adds multer integration.
crates/rustapi-core/src/lib.rs Re-exports production defaults config, health endpoint config/response, streaming multipart, sse_from_iter.
crates/rustapi-core/src/health.rs Adds HealthEndpointConfig, HealthResponse, and helper handlers + OpenAPI response modifier.
crates/rustapi-core/src/extract.rs Adds OpenAPI OperationModifier for AsyncValidatedJson<T> (parity with ValidatedJson<T>).
crates/rustapi-core/src/app.rs Adds health endpoint wiring and a ProductionDefaultsConfig + production_defaults* APIs.
crates/rustapi-core/examples/perf_snapshot.rs New synthetic in-process perf snapshot example for CI/local runs.
crates/rustapi-core/Cargo.toml Adds multer = "3" and enables tokio io-util feature.
crates/cargo-rustapi/tests/cli_tests.rs Adds tests for presets and new commands’ help output.
crates/cargo-rustapi/src/templates/mod.rs Adds ProjectPreset with recommended feature bundles.
crates/cargo-rustapi/src/commands/observability.rs New observability command that surfaces workflow assets.
crates/cargo-rustapi/src/commands/new.rs Adds --preset support and merges preset features with explicit features.
crates/cargo-rustapi/src/commands/mod.rs Registers new bench and observability commands (and replay under feature).
crates/cargo-rustapi/src/commands/bench.rs New bench command intended to run a repo benchmark script.
crates/cargo-rustapi/src/cli.rs Wires new subcommands into CLI; changes replay wiring.
crates/cargo-rustapi/README.md Documents new commands and presets.
crates/cargo-rustapi/Cargo.toml Enables replay by default feature set.
api/public/rustapi-rs.default.txt Updates public API snapshot for new exports (streaming multipart, sse_from_iter).
api/public/rustapi-rs.all-features.txt Updates all-features snapshot for new exports (oauth2/session/jobs/replay/etc.).
RELEASES.md Adds benchmark policy note pointing to canonical doc.
README.md Adds probe and replay examples; replaces static perf number with benchmark-policy pointer.
Cargo.lock Adds new dependency lock entries (multer, redis, etc.).
CHANGELOG.md Adds note that old benchmark numbers are historical snapshots.
.gitignore Adds ignores for production docs, internal GH assets, and *.md (very broad).
.github/workflows/benchmark.yml Adds perf snapshot run and uploads perf_snapshot.txt artifact.
.env Adds placeholder env vars for local docs/examples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 7 to 72
@@ -33,9 +35,15 @@ enum Commands {
/// Add a feature or dependency
Add(AddArgs),

/// Run the benchmark workflow
Bench(BenchArgs),

/// Check environment health
Doctor(DoctorArgs),

/// Surface observability docs and baseline workflow assets
Observability(ObservabilityArgs),

/// Generate code from templates
#[command(subcommand)]
Generate(GenerateArgs),
@@ -59,9 +67,8 @@ enum Commands {
Deploy(DeployArgs),

/// Replay debugging commands (time-travel debugging)
#[cfg(feature = "replay")]
#[command(subcommand)]
Replay(commands::ReplayArgs),
Replay(ReplayArgs),
}
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReplayArgs is imported behind #[cfg(feature = "replay")], but the Commands::Replay(ReplayArgs) variant (and its match arm) are unconditional. Building cargo-rustapi with default-features = false (or without replay) will fail to compile. Either gate the enum variant + match arm behind the same feature, or make the replay command always available and remove the conditional import/module gating.

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +61
let script_path = workspace_root.join("scripts").join("bench.ps1");

if !script_path.exists() {
bail!(
"Benchmark script was not found at {}",
script_path.display()
);
}

let shell = if cfg!(windows) { "powershell" } else { "pwsh" };

println!(
"{} {}",
style("Running benchmark workflow from").bold(),
style(script_path.display()).cyan()
);

let mut command = Command::new(shell);
if cfg!(windows) {
command.args(["-ExecutionPolicy", "Bypass", "-File"]);
} else {
command.arg("-File");
}
command.arg(&script_path).current_dir(&workspace_root);

if let Some(warmup) = args.warmup {
command.env("RUSTAPI_PERF_WARMUP", warmup.to_string());
}
if let Some(iterations) = args.iterations {
command.env("RUSTAPI_PERF_ITERS", iterations.to_string());
}

let status = command.status().await.context("Failed to launch benchmark workflow")?;
if !status.success() {
bail!("Benchmark workflow exited with status {}", status);
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo rustapi bench hard-codes scripts/bench.ps1, but this repository currently has no scripts/ directory (so the command will always error). Consider either adding scripts/bench.ps1 in this PR, or updating the command to run cargo bench --workspace and the perf_snapshot example directly (matching docs/PERFORMANCE_BENCHMARKS.md and CI).

Suggested change
let script_path = workspace_root.join("scripts").join("bench.ps1");
if !script_path.exists() {
bail!(
"Benchmark script was not found at {}",
script_path.display()
);
}
let shell = if cfg!(windows) { "powershell" } else { "pwsh" };
println!(
"{} {}",
style("Running benchmark workflow from").bold(),
style(script_path.display()).cyan()
);
let mut command = Command::new(shell);
if cfg!(windows) {
command.args(["-ExecutionPolicy", "Bypass", "-File"]);
} else {
command.arg("-File");
}
command.arg(&script_path).current_dir(&workspace_root);
if let Some(warmup) = args.warmup {
command.env("RUSTAPI_PERF_WARMUP", warmup.to_string());
}
if let Some(iterations) = args.iterations {
command.env("RUSTAPI_PERF_ITERS", iterations.to_string());
}
let status = command.status().await.context("Failed to launch benchmark workflow")?;
if !status.success() {
bail!("Benchmark workflow exited with status {}", status);
println!(
"{} {}",
style("Running `cargo bench --workspace` in").bold(),
style(workspace_root.display()).cyan()
);
let mut bench_cmd = Command::new("cargo");
bench_cmd
.arg("bench")
.arg("--workspace")
.current_dir(&workspace_root);
if let Some(warmup) = args.warmup {
bench_cmd.env("RUSTAPI_PERF_WARMUP", warmup.to_string());
}
if let Some(iterations) = args.iterations {
bench_cmd.env("RUSTAPI_PERF_ITERS", iterations.to_string());
}
let bench_status = bench_cmd
.status()
.await
.context("Failed to run `cargo bench --workspace`")?;
if !bench_status.success() {
bail!("`cargo bench --workspace` exited with status {}", bench_status);
}
println!(
"{} {}",
style("Running `cargo run --example perf_snapshot --release` in").bold(),
style(workspace_root.display()).cyan()
);
let mut perf_cmd = Command::new("cargo");
perf_cmd
.arg("run")
.arg("--example")
.arg("perf_snapshot")
.arg("--release")
.current_dir(&workspace_root);
if let Some(warmup) = args.warmup {
perf_cmd.env("RUSTAPI_PERF_WARMUP", warmup.to_string());
}
if let Some(iterations) = args.iterations {
perf_cmd.env("RUSTAPI_PERF_ITERS", iterations.to_string());
}
let perf_status = perf_cmd
.status()
.await
.context("Failed to run `cargo run --example perf_snapshot --release`")?;
if !perf_status.success() {
bail!(
"`cargo run --example perf_snapshot --release` exited with status {}",
perf_status
);

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +46
let assets = [
(
"Production baseline",
workspace_root.join("docs").join("PRODUCTION_BASELINE.md"),
),
(
"Observability cookbook",
workspace_root
.join("docs")
.join("cookbook")
.join("src")
.join("recipes")
.join("observability.md"),
),
(
"Benchmark workflow",
workspace_root.join("scripts").join("bench.ps1"),
),
(
"Quality gate",
workspace_root.join("scripts").join("check_quality.ps1"),
),
];
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The observability command treats several paths as required assets (docs/PRODUCTION_BASELINE.md, scripts/bench.ps1, scripts/check_quality.ps1), but those files/directories are not present in the repo. As a result, cargo rustapi observability --check will reliably fail (and the output will always report missing assets). Either add these assets in this PR or adjust the asset list to match what actually exists (e.g., .github/workflows/benchmark.yml and the benchmark commands it runs).

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +35
Use the repository benchmark script:

```powershell
./scripts/bench.ps1
```

This currently runs:

```powershell
cargo bench --workspace
cargo run -p rustapi-core --example perf_snapshot --release
```
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc instructs users to run ./scripts/bench.ps1, but the repository doesn't include that script right now. Either add the script in this PR, or update the docs to point at the actual benchmark entry points that exist (e.g., cargo bench --workspace and cargo run -p rustapi-core --example perf_snapshot --release).

Copilot uses AI. Check for mistakes.
Comment on lines +87 to +96
### Run benchmarks locally

From the repository root:

```powershell
./scripts/bench.ps1
```
</details>

That currently executes `cargo bench --workspace`.

Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section references ./scripts/bench.ps1, but the repository doesn't currently contain that script. To avoid sending users to a dead command, update this to the actual benchmark invocation(s) that exist in-repo (or add the script as part of this PR).

Copilot uses AI. Check for mistakes.
Comment on lines +96 to +117
```yaml
livenessProbe:
httpGet:
path: /live
port: 8080
initialDelaySeconds: 5
periodSeconds: 10

readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 2
periodSeconds: 5

startupProbe:
httpGet:
path: /live
port: 8080
failureThreshold: 30
periodSeconds: 2
```
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Kubernetes YAML example uses tab characters for indentation. YAML requires spaces, so as-written this snippet will fail to parse if copied into a manifest. Replace the tabs with spaces and keep indentation consistent (typically 2 spaces) so the example is valid.

Copilot uses AI. Check for mistakes.
OAUTH_CLIENT_ID=replace-me
OAUTH_CLIENT_SECRET=replace-me
OAUTH_REDIRECT_URI=http://127.0.0.1:3000/auth/callback
OIDC_ISSUER_URL=https://accounts.google.com
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Committing a root .env file can cause accidental leakage if developers later add real secrets, and it can also unexpectedly affect local runs/CI that auto-load .env. Consider renaming this to .env.example (tracked) and adding .env to .gitignore, while keeping the docs pointing at the example file.

Suggested change
OIDC_ISSUER_URL=https://accounts.google.com
OIDC_ISSUER_URL=replace-me

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +18
| [GraphQL Adapter Plan](GRAPHQL_ADAPTER_PLAN.md) | Planned GraphQL integration shape and facade design |
| [Adaptive Execution Debug Plan](ADAPTIVE_EXECUTION_DEBUG_PLAN.md) | Proposed profiling/debug UX for making execution tiers visible in traces, logs, metrics, and headers |
| [Performance Benchmarks](PERFORMANCE_BENCHMARKS.md) | Authoritative source for benchmark methodology and published claims |
| [Recommended Production Baseline](PRODUCTION_BASELINE.md) | Opinionated starting point for production services |
| [Production Checklist](PRODUCTION_CHECKLIST.md) | Rollout-ready operational checklist |
| [Cookbook: Replay Workflow](cookbook/src/recipes/replay.md) | Official capture → inspect → replay → diff flow for time-travel debugging |
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PRODUCTION_BASELINE.md and PRODUCTION_CHECKLIST.md are linked here, but those files are not present under docs/ in the repository. This creates broken links in the docs landing page; either add the missing documents in this PR or remove/adjust the links until they exist.

Copilot uses AI. Check for mistakes.
Comment on lines +8 to 20
## Ne zaman kullanılır?

Add the `replay` feature to your `Cargo.toml`:
Replay en çok şu durumlarda işe yarar:

- staging ile local arasında davranış farkı varsa
- bir regresyonu gerçek trafik örneğiyle yeniden üretmek istiyorsanız
- yeni bir sürümü canary ortamına almadan önce kritik istekleri tekrar koşturmak istiyorsanız
- “bu istek neden dün çalışıyordu da bugün bozuldu?” sorusuna zaman makinesi tadında cevap arıyorsanız

## Ön koşullar

Uygulamada canonical replay feature'ını açın:

Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This recipe switches from English to Turkish starting at the first section heading. If the cookbook is intended to be English-first, this makes the page inconsistent and harder to consume for most readers. Consider translating these sections to English (or splitting into localized copies with clear navigation/labels).

Copilot uses AI. Check for mistakes.
Tuntii added 4 commits March 8, 2026 22:20
Enable the `sync` feature for tokio in cargo-rustapi and gate the Replay CLI subcommand/tests behind cfg(feature = "replay"). Additionally apply a series of small refactors and formatting fixes across the workspace: reflowed long expressions, added/removed trailing commas, normalized imports and multi-line signatures, and cleaned up test invocations and assertions. Changes touch cargo-rustapi, rustapi-core, rustapi-extras, rustapi-rs and related examples/tests; they are primarily stylistic and readability improvements (with the notable functional addition of the tokio `sync` feature and conditional replay wiring).
@Tuntii Tuntii merged commit f90345c into main Mar 8, 2026
7 checks passed
github-actions bot pushed a commit that referenced this pull request Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants