Skip to content

feat: mimic the Fault Injector API - #6

Merged
nkaradzhov merged 5 commits into
redis-developer:masterfrom
nkaradzhov:scenarios
Sep 10, 2026
Merged

nkaradzhov merged 5 commits into
redis-developer:masterfrom
nkaradzhov:scenarios

Conversation

@nkaradzhov

@nkaradzhov nkaradzhov commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator
  • POST /action + GET /action/:id — submit actions, poll status (pending/running/success/failed)
  • GET /action — list submitted actions
  • slot_migrate action — effects: remove-add, remove, add, slot-shuffle, with SMIGRATING/SMIGRATED push notifications to all clients, incl. connections opened mid-migration
  • create_database action — sizes the proxy cluster to shards_count, returns raw_endpoints/bdb_id/credentials
  • reset_cluster action — restores initial topology and interceptors
  • GET /slot-migrate?effect= — FI-shaped triggers (migrate, maintenance_mode, failover) with full dbconfig requirements
  • POST /reject-traffic/start / POST /reject-traffic/stop — simulate the endpoints going offline (drop all connections, refuse new ones) and back online
  • Action type enum at FI parity; migration delays overridable via MIGRATION_DELAY_MS / COMPLETION_DELAY_MS
  • Removed dead /scenarios code; new test coverage for all of the above

🤖 Generated with Claude Code

nkaradzhov and others added 5 commits September 10, 2026 13:34
…tion

- Add POST /scenarios/predefined/:scenario endpoint with Zod validation
- Create scenarios folder structure similar to default_interceptors
- Implement remove-add scenario:
  - Picks a random node from existing proxies
  - Adds a new node with auto-incremented port
  - Intercepts CLUSTER SLOTS to exclude picked node and include new node
  - Sends SMIGRATING notification (slots about to migrate)
  - Sends SMIGRATED notification (slots migrated to new node)
- Add helper functions for scenario operations:
  - buildSMigratingNotification() - RESP3 SMIGRATING notification
  - buildSMigratedNotification() - RESP3 SMIGRATED notification
  - createCustomClusterSlotsInterceptor() - custom cluster slots response
  - getSlotRangesForProxy() - calculate slot ranges for a proxy
  - addNode() - add new proxy node
  - sendToAllClients() - broadcast to all clients
  - pickRandom() - random element selection
  - findNextAvailablePort() - find next available port
- Add bar scenario skeleton for future implementation
Implement action-based API matching the Fault Injector interface for
executing Redis cluster operations with slot migration simulation.

New API endpoints:
- POST /action - Submit an action for async execution
- GET /action/:action_id - Poll action status and result
- GET /slot-migrate - List triggers for slot migration effects

Implemented slot migration effects:
- remove-add: Remove one node and add a new one
- remove: Remove a node and redistribute slots
- add: Add a new node and rebalance slots
- slot-shuffle: Redistribute slots across existing nodes

Each effect sends SMIGRATING/SMIGRATED push notifications to connected
clients and updates CLUSTER SLOTS interceptors accordingly.

Removed deprecated /scenarios endpoints in favor of the new action API.
Make the proxy's action API a drop-in stand-in for the Fault Injector
(re_fault_injector) so FI clients work against it unchanged:

- Implement reset_cluster: restore the initial proxy topology and
  reapply default interceptors.
- Implement create_database: size the proxy cluster to
  database_config.shards_count and return raw_endpoints, username,
  password, tls and bdb_id in the action output, matching what FI
  clients parse.
- Add GET /action to list submitted actions.
- Report "running" while an action executes and return structured
  action output instead of the hardcoded "Done".
- Generate FI-shaped triggers for GET /slot-migrate: real trigger
  names (migrate, maintenance_mode, failover), descriptions, and full
  dbconfig requirements with ext-ip/ext-hostname names, mirroring the
  FI's TRIGGER_DEFINITIONS and dbconfig templates.
- Broadcast SMIGRATING/SMIGRATED to clients on every node during
  remove and remove-add, so each cluster connection observes the
  migration.
- Push SMIGRATING to connections opened during an active migration,
  matching how a real cluster treats new connections mid-migration.
- Complete the action type enum to FI parity (reset_cluster,
  topology_change_standalone, network_latency,
  wait_for_database_active, collect_debuginfo).
- Make migration delays env-overridable (MIGRATION_DELAY_MS,
  COMPLETION_DELAY_MS) so tests run fast.
- Remove the dead /scenarios modules and their stale tests; cover the
  action API with new tests instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
POST /reject-traffic/start drops every client connection and stops
accepting new ones on all nodes. POST /reject-traffic/stop brings the
listeners back up. Interceptors and topology survive the cycle, and
both endpoints are idempotent.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@bobymicroby bobymicroby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@nkaradzhov
nkaradzhov merged commit c46a5e2 into redis-developer:master Sep 10, 2026
1 check passed
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