Delay Features
Simulate network conditions with delay patterns controlled via HTTP headers or environment variables. Delays are capped at 300s to prevent hangs. Prometheus histograms track latency.
Control Flow
graph TD
A[Request] --> B{Check Headers/Env}
B -->|X-Echo-Delay| C[Simple Delay]
B -->|X-Echo-Jitter| D[Jitter Delay]
B -->|X-Echo-Random-Delay| E[Random Delay]
B -->|X-Echo-Exponential| F[Exponential Backoff]
B -->|X-Echo-Latency| G[Latency Injection]
C --> H[Apply Delay]
D --> H
E --> H
F --> H
G --> H
H --> I[Continue Processing]
Simple Delay
Applies a fixed delay in milliseconds.
- Header:
X-Echo-Delay: 500ms - Env:
ECHO_DELAY=100ms - Max: 300000ms (300s)
- Example:
curl -H "X-Echo-Delay: 200ms" http://localhost:8080/ -d "test"
# Logs: "Simple delay: 200ms"
Jitter Delay
Base delay ± random variance (ms).
- Header:
X-Echo-Jitter: 100,50(100ms ± 50ms) - Env:
ECHO_JITTER=200,100 - Bounds: Delay clamped to 0–300000ms
- Example: Delays ~150-250ms randomly
curl -H "X-Echo-Jitter: 100,50" http://localhost:8080/
# Logs: "Jitter delay: 120ms (base: 100ms, jitter: 20ms)"
Random Delay
Uniform random delay in a range (ms).
- Header:
X-Echo-Random-Delay: 100,500 - Env:
ECHO_RANDOM_DELAY=50,200 - Bounds: Max capped at 300000ms
- Example:
curl -H "X-Echo-Random-Delay: 100,300" http://localhost:8080/
# Logs: "Random delay: 150ms (range: 100-300)"
Exponential Backoff
Delay = base * 2^(attempt-1) + 25% jitter, for retry testing.
- Header:
X-Echo-Exponential: 100,3(~400ms + jitter) - Env:
ECHO_EXPONENTIAL=50,2 - Bounds: Result clamped to 0–300000ms
- Example:
curl -H "X-Echo-Exponential: 100,3" http://localhost:8080/
# Logs: "Exponential delay: 410ms (base: 100ms, attempt: 3)"
Latency Injection
Fixed or random latency (ms).
- Header:
X-Echo-Latency: 100msor100-200ms - Env:
ECHO_LATENCY=50-150 - Bounds: Clamped to 0–300000ms
- Example:
curl -H "X-Echo-Latency: 100-200ms" http://localhost:8080/
# Logs: "Latency injection: 130ms (range: 100-200)"
Notes
- Only one delay type applies per request (first matched: Simple, Jitter, Random, Exponential, Latency).
- Maximum delay: 300s to prevent abuse.
- Check
/metricsforecho_request_duration_secondshistogram.