This document describes how to confgure time chaos experiments in Chaos Mesh.

Time chaos is used to modify the return value of clock_gettime, which leads to time offset on go's time.Now(), rust std's 'std::time::Instant::now()' etc.

Below is a sample time chaos configuration file:

  1. apiVersion: pingcap.com/v1alpha1
  2. kind: TimeChaos
  3. metadata:
  4. name: time-shift-example
  5. namespace: chaos-testing
  6. spec:
  7. mode: one
  8. selector:
  9. namespaces:
  10. - tidb-cluster-demo
  11. labelSelectors:
  12. "app.kubernetes.io/component": "pd"
  13. timeOffset:
  14. sec: 100000
  15. nsec: 100000
  16. clockIds:
  17. - CLOCK_REALTIME
  18. duration: "10s"
  19. scheduler:
  20. cron: "@every 15s"

For more sample files, see examples. You can edit them as needed.

Description:

  • mode defines the mode to select pods.
  • selector specifies the target pods for chaos injection.
  • timeOffset specifies the offset of time. sec means the offset of seconds and nsec means the offset of nanoseconds.
  • clockIds defines all affected clk_id. clk_id refers to the first argument of clock_gettime call. For most application, CLOCK_REALTIME is enough.
  • duration defines the duration for each chaos experiment. In the sample file above, the time chaos lasts for 10 seconds.
  • scheduler defines the scheduler rules for the running time of the chaos experiment. For more rule information, see https://godoc.org/github.com/robfig/cron.

Limitations

  • Time modification will only be injected into the main process of container.
  • Time chaos has no effect on pure syscall clock_gettime.
  • All injected vdso call will use pure syscall to get realtime, so clock related function call will be much slower.