feat(seatbelt): introduce chaos injection middleware#335
feat(seatbelt): introduce chaos injection middleware#335
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #335 +/- ##
========================================
Coverage 100.0% 100.0%
========================================
Files 207 210 +3
Lines 15403 15552 +149
========================================
+ Hits 15403 15552 +149 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds a new chaos injection middleware to the seatbelt crate, enabling controlled fault/output injection into service pipelines for resilience testing.
Changes:
- Introduces
seatbelt::chaos::injectionmiddleware (layer + service + config + docs) with optional TowerServicesupport. - Adds an example (
examples/chaos_injection.rs) and integration tests covering layered + tower execution paths. - Extends telemetry/metrics plumbing and feature gating to include the new middleware (and ensures resilience event counter is available for more middleware combinations).
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/seatbelt/tests/chaos_injection.rs | Integration tests for chaos injection behavior (layered + tower). |
| crates/seatbelt/src/metrics.rs | Expands cfg gating so resilience event counter is available for additional middleware/features. |
| crates/seatbelt/src/lib.rs | Documents chaos testing, adds chaos module export, updates feature gating. |
| crates/seatbelt/src/context.rs | Allows telemetry helper creation when chaos-injection is enabled. |
| crates/seatbelt/src/chaos/mod.rs | Adds the new top-level chaos module and docs. |
| crates/seatbelt/src/chaos/injection/telemetry.rs | Defines the chaos injection telemetry event name. |
| crates/seatbelt/src/chaos/injection/service.rs | Implements the injection middleware and telemetry emission + unit tests. |
| crates/seatbelt/src/chaos/injection/mod.rs | Public module docs and re-exports for injection. |
| crates/seatbelt/src/chaos/injection/layer.rs | Builder/type-state layer for configuring injection. |
| crates/seatbelt/src/chaos/injection/config.rs | Serializable config for injection middleware + tests. |
| crates/seatbelt/src/chaos/injection/callbacks.rs | Callback wrapper type for injected output factory. |
| crates/seatbelt/src/chaos/injection/args.rs | Callback args type for injected output factory. |
| crates/seatbelt/examples/chaos_injection.rs | Example demonstrating injection usage. |
| crates/seatbelt/Cargo.toml | Adds chaos-injection feature and registers the new example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 17 out of 18 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace manual assertions with insta snapshots in config, layer, and service tests where the pattern is setting values and asserting state: - config::default_values -> default_snapshot (assert_json_snapshot) - layer::new_needs_rate_and_output (assert_debug_snapshot) - layer::config_sets_rate_and_enabled -> config_applies_all_settings (assert_debug_snapshot) - service::injection_future_debug_contains_struct_name -> injection_future_debug_snapshot (assert_debug_snapshot) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 23 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Very nice. What would you think of a variation on this which is "pretend endpoint N is completely dead for the next N seconds". This would provide another tool to test out recovery logic. |
This is already possible with a custom |
|
Maybe add an example then of how to simulate an extended outage? |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 23 out of 24 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add chaos injection middleware
Introduces
Injection, a new middleware underseatbelt::chaos::injectionthat replaces service output with a user-provided value at a configurable probability. Gated behind thechaos-injectionfeature flag.API
Highlights
rate+outputare set before useServiceimpls —layered::Serviceandtower_service::Servicerate()clamps to[0.0, 1.0]instead of panickingoutput_with()receives consumed input for context-aware fault generationInjectionConfigwith serde support for file-based configurationresilience.eventcounter (chaos.injection) + structured logenable_if/disablefor conditional activationChanges
chaos-injection(depends onfastrand)src/chaos/injection/(8 files)examples/chaos_injection.rstests/chaos_injection.rs(18 tests via rstest, layered + tower)lib.rs,context.rs,metrics.rsfeature gates