Background
The CFG allows users to create custom fault actions for chaotic experiments. Users can configure action parameters and execute script commands based on specific scenarios.
Practical Examples
This section demonstrates how to configure custom actions to perform chaos engineering experiments for CVM CPU accumulation faults.
Step 1: Experiment preparation
A CVM instance used for fault injection (The example instance runs TencentOS Server 2.6 (Final).)
Fault action script file
Step 2: Create custom actions
2. Configure the custom actions. Configure command content and command parameters. Click Save after completing the configuration.
The example command content is as follows, where the percentage, timeout, and step parameters can be passed during execution.
#!/bin/bash
user=$(whoami)
if [ !$user == 'root' ]
then
sudo -i
fi
echo -e "["`date +"%Y-%m-%d %H:%M:%S"`"] \\c"
echo "installing stress-ng..."
yum install stress-ng -y
percentage={{percentage}}
timeout={{timeout}}
step={{step}}
for (( i = $step; i < ${timeout} + $step; i=(i+step) )); do
val=`expr $percentage \\* $i / $timeout`
echo "Pre = $val"
stress-ng -c 0 -l $val --timeout $step
done
if [[ !$? -eq 0 ]]
then
echo -e "["`date +"%Y-%m-%d %H:%M:%S"`"] \\c"
echo "Failed"
exit 1
else
echo -e "["`date +"%Y-%m-%d %H:%M:%S"`"] \\c"
echo "Completed"
exit 0
fi
Step 3: Experiment orchestration
1. Enter the Experiment Management page and click Create a New Experiment.
2. Click Skip and create a blank experiment, fill in the experiment details, and select the objective CVM instance for the experiment.
3. Add experiment actions. Click Add Now, select Shell Script , select the created Custom action, and click Next .
4. Leave the action parameters as default and click Confirm.
5. After configuring action parameters, click Next. After confirming all configurations, add a monitoring metric to observe the action's effect, then click Submit.
6. Click Submit to complete the experiment creation.
Step 4: Execute the experiment
1. Execute the experiment and observe the execution results.
2. During execution, users can monitor CPU data changes via monitoring metrics. After waiting for 90 seconds, once the action is completed, you can see from the monitoring metrics that the experiment results meet the expectations.
Was this page helpful?