Configuration
- Options:
ChaosLatencyStrategyOptions - Extensions:
AddChaosLatency
Basic usage
Here are several ways to configure the latency chaos strategy:Complete example
Here’s a complete example showing latency injection with timeout and retry:Strategy options
If both
Latency and LatencyGenerator are specified then Latency will be ignored.Use cases
Latency injection is useful for:- Testing timeout handling: Verify that your timeout and retry strategies work correctly when operations are slow
- Simulating network delays: Test how your application behaves with high network latency
- Validating user experience: Ensure your UI remains responsive and provides appropriate feedback during slow operations
- Performance testing: Identify bottlenecks and areas where caching or optimization would help
- Testing distributed systems: Simulate slow microservices or database queries
Dynamic latency injection
You can useLatencyGenerator to inject different latencies based on context:
Telemetry
The latency chaos strategy reports the following telemetry events:
Here are some sample events:
The
Chaos.OnLatency telemetry event will be reported only if the latency chaos strategy injects a positive delay. If the latency is not injected, or if injected but the latency is negative, or if the LatencyGenerator throws an exception, then there will be no telemetry emitted. Also, the Result will be always empty for the Chaos.OnLatency telemetry event.How it works
Normal execution (no chaos)
Chaos execution (latency injected)
Unlike fault injection, latency injection does not prevent the user’s callback from being invoked. The delay is injected before the callback is executed.