JVMChaos allows you to inject various types of faults into Java Virtual Machine (JVM) applications using Byteman rules. This enables testing application resilience to exceptions, latency, modified return values, and resource stress.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.
Actions
JVMChaos supports the following actions:- latency: Add latency to method invocations
- return: Modify method return values
- exception: Throw custom exceptions from methods
- stress: Stress CPU or memory resources
- gc: Trigger garbage collection
- ruleData: Inject faults using custom Byteman rules
- mysql: Inject faults into MySQL JDBC connections
Spec Fields
The JVM chaos action to perform.Options:
latency, return, exception, stress, gc, ruleData, mysqlDuration of the chaos action (e.g.,
30s, 5m, 1h).Selection mode for target pods.Options:
one, all, fixed, fixed-percent, random-max-percentList of container names to affect. If not set, the first container will be injected.
Common Parameters
Port of the agent server.Default:
9277Process ID of the Java process to attach to.
Method Targeting (latency, return, exception)
Java class name to target.
Method name in the Java class to target.
Action-Specific Parameters
Latency Action
Latency duration in milliseconds.
Return Action
The return value to use (as string representation).
Exception Action
The exception to throw, including constructor arguments.Example:
java.io.IOException("BOOM")Stress Action
Number of CPU cores to stress.
Memory type to stress.Options:
stack, heapRuleData Action
Custom Byteman rule data. See Byteman Rule Language for syntax.
Byteman rule name. Should be unique. Will be generated if not set.
MySQL Action
Version of mysql-connector-java.Options:
5 (for 5.X.X), 8 (for 8.X.X)Database name to match. Empty string matches all databases.
Table name to match. Empty string matches all tables.
SQL statement type to match. Empty string matches all types.Options:
select, insert, update, delete, replaceRemote cluster name where the chaos will be deployed.
Examples
Throw Exception
IOException whenever the sayhello method is called in the Main class.
Modify Return Value
getnum method to return 9999 instead of its normal return value.
Custom Byteman Rule
Add Latency to Method
processRequest method in 50% of the targeted pods.
Trigger Garbage Collection
Prerequisites
- Java Agent: The target JVM must have the Chaos Mesh Java agent attached
- Agent Server Port: The agent server must be accessible (default port 9277)
- Byteman: Uses Byteman for rule injection
Implementation Details
JVMChaos works by:- Connecting to the Chaos Mesh Java agent running in the target pod
- Injecting Byteman rules into the JVM
- The rules intercept method calls and modify behavior according to the action
api/v1alpha1/jvmchaos_types.go:22-70
MySQL Fault Injection
The MySQL action allows injecting faults into MySQL connections. The fault is only triggered when all matching conditions are met:- SQL statement matches the database (or database is empty)
- SQL statement matches the table (or table is empty)
- SQL statement matches the sqlType (or sqlType is empty)
database: "test", table: "t1", sqlType: "select", only SELECT statements on test.t1 will be affected.
Source: api/v1alpha1/jvmchaos_types.go:136-158