TimeChaos allows you to shift time forward or backward for target pods to test how your application handles time-related issues, clock skew, and time synchronization problems.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/chaos-mesh/chaos-mesh/llms.txt
Use this file to discover all available pages before exploring further.
Supported Actions
TimeChaos provides time offset injection:- Time Shift: Offset system time by a specified duration (forward or backward)
- Clock Selection: Target specific system clocks
Configuration
Basic Example
Spec Fields
Specifies the target pods for the chaos experiment. See PodChaos documentation for selector details.
Selection mode:
one, all, fixed, fixed-percent, or random-max-percentTime offset to inject. A possibly signed sequence of decimal numbers with unit suffix. Examples:
"10m"- shift time forward by 10 minutes"-1h"- shift time backward by 1 hour"5s500ms"- shift time forward by 5.5 seconds"-10m100ns"- shift time backward by 10 minutes and 100 nanoseconds
ns, us (or µs), ms, s, m, hList of clock IDs to affect. Available options:
CLOCK_REALTIME- System-wide real-time clockCLOCK_MONOTONIC- Monotonic clock (not affected by time adjustments)CLOCK_PROCESS_CPUTIME_ID- Per-process CPU timeCLOCK_THREAD_CPUTIME_ID- Per-thread CPU timeCLOCK_MONOTONIC_RAW- Raw monotonic clockCLOCK_REALTIME_COARSE- Faster but less precise real-time clockCLOCK_MONOTONIC_COARSE- Faster but less precise monotonic clockCLOCK_BOOTTIME- Time since boot (includes suspended time)CLOCK_REALTIME_ALARM- Real-time clock for alarmsCLOCK_BOOTTIME_ALARM- Boot time clock for alarms
["CLOCK_REALTIME"]Duration of the chaos action. Format: “300ms”, “1.5h”, “2h45m”
List of container names to inject time chaos into. If not set, the first container will be injected.
Remote cluster where chaos will be deployed
Examples
Shift Time Backward
Shift time backward by 10 minutes:Shift Time Forward
Shift time forward by 1 hour:Target Multiple Clocks
Affect both real-time and monotonic clocks:Precise Time Offset
Use nanosecond precision:Use Cases
Testing Time-Based Logic
Shift time to test:- Expiration logic (tokens, sessions, certificates)
- Scheduled tasks and cron jobs
- Time-based access control
- Lease and lock timeouts
Distributed System Clock Skew
Simulate clock drift between nodes to test:- Distributed consensus algorithms (Raft, Paxos)
- Clock synchronization dependencies
- Causality tracking in distributed systems
- Event ordering and timestamping
Database Time Dependencies
Test database behaviors with time changes:- Time-based partitioning
- MVCC (Multi-Version Concurrency Control)
- Timestamp-based conflict resolution
- TTL (Time To Live) mechanisms
Certificate and Token Expiration
Simulate future time to test:- TLS certificate expiration handling
- OAuth token expiration and refresh
- API key rotation
- License expiration
Best Practices
- Start Small: Begin with small time offsets (seconds to minutes) to understand impact
- Understand Clock Types:
- Use
CLOCK_REALTIMEfor wall-clock time (most common) CLOCK_MONOTONICfor elapsed time measurements- Be cautious with system-critical clocks
- Use
- Test Both Directions: Test both forward and backward time shifts to catch different edge cases
- Duration Management: Use appropriate durations - too short may not trigger issues, too long can cause cascading failures
- Gradual Rollout: Start with
mode: oneto test impact on a single pod - Monitor Side Effects: Watch for:
- Authentication failures
- Certificate validation errors
- Timeout issues
- Database replication lag
- Log timestamp anomalies
- Container Selection: Specify
containerNameswhen working with multi-container pods to control which containers experience time shift - Combine with Other Chaos: Test time chaos in combination with network delays or partitions for realistic distributed system scenarios
Clock ID Reference
CLOCK_REALTIME
System-wide real-time clock. This is the most commonly used clock for wall-clock time. It can be adjusted by administrators or NTP.
CLOCK_MONOTONIC
Monotonic clock that measures time from an unspecified starting point. It’s not affected by manual time adjustments but is affected by NTP adjustments.
CLOCK_PROCESS_CPUTIME_ID
High-resolution per-process timer measuring CPU time consumed by the process.
CLOCK_THREAD_CPUTIME_ID
Thread-specific CPU-time clock.
CLOCK_MONOTONIC_RAW
Similar to CLOCK_MONOTONIC but not affected by NTP adjustments.
CLOCK_BOOTTIME
Identical to CLOCK_MONOTONIC but includes time spent in suspend.
Notes
- TimeChaos is implemented using system call interception
- Time changes are isolated to the target container(s) and don’t affect the host or other containers
- The chaos daemon intercepts time-related system calls (clock_gettime, gettimeofday, time)
- Applications that cache time values may not immediately reflect the time shift
- Time offset is relative to the actual system time
- Multiple TimeChaos experiments on the same pod will compound their effects
- Some applications may validate time consistency and fail if they detect anomalies
- Time shifts can affect log timestamps, making troubleshooting more complex