Version: 2.1.4

Simulate Time Faults

TimeChaos Introduction

Chaos Mesh provides the TimeChaos experiment type. You can use this experiment type to simulate a time offset scenario. This document describes how to create a TimeChaos experiment and its associated configuration file.

note

TimeChaos only affects the PID 1 process in the PID namespace of the container, and child processes of the PID 1. For example, the process started by kubectl exec does not be affected.

You can create experiments in Chaos Dashboard or using the YAML configuration file.

Create experiments using Chaos Dashboard

  1. Open Chaos Dashboard, and click NEW EXPERIMENT on the page to create a new experiment:

    Create Experiment

  2. In the Choose a Target area, choose CLOCK SCREW and fill out the Clock ID and time offset.

    TimeChaos Experiments

  3. Fill out the experiment information, and specify the experiment scope and the scheduled experiment duration:

    Experiment Information

  4. Submit the experiment information.

Create experiments using the YAML file

  1. Write the experiment configuration to the YAML configuration file. In the following example, the time-shift.yaml file is used.

    1. apiVersion: chaos-mesh.org/v1alpha1
    2. kind: TimeChaos
    3. metadata:
    4. name: time-shift-example
    5. namespace: chaos-testing
    6. spec:
    7. mode: one
    8. selector:
    9. labelSelectors:
    10. 'app': 'app1'
    11. timeOffset: '-10m100ns'

    This experiment configuration will shift the time of the processes in the specified Pod forward by 10 minutes and 100 nanoseconds.

  2. After the configuration file is prepared, use kubectl to create an experiment:

    1. kubectl apply -f time-shift.yaml

The fields in the YAML configuration file are described in the following table:

ParameterTypeNoteDefault valueRequiredExample
timeOffsetstringSpecifies the length of time offset.NoneYes-5m
clockIds[]stringSpecifies the ID of clock that will be offset. See the clock_gettime documentation for details.[“CLOCK_REALTIME”]No[“CLOCK_REALTIME”, “CLOCK_MONOTONIC”]
modestringSpecifies the mode of the experiment. The mode options include one (selecting a random Pod), all (selecting all eligible Pods), fixed (selecting a specified number of eligible Pods), fixed-percent (selecting a specified percentage of Pods from the eligible Pods), and random-max-percent (selecting the maximum percentage of Pods from the eligible Pods).NoneYesone
valuestringProvides parameters for the mode configuration, depending on mode.For example, when mode is set to fixed-percent, value specifies the percentage of Pods.NoneNo1
containerNames[]stringSpecifies the name of the container into which the fault is injected.NoneNo[“nginx”]
selectorstructSpecifies the target Pod. For details, refer to Define the experiment scope.NoneYes