Simulieren von JVM-Anwendungsfehlern
Diese Seite wurde von PageTurner AI übersetzt (Beta). Nicht offiziell vom Projekt unterstützt. Fehler gefunden? Problem melden →
Chaosd simuliert JVM-Anwendungsfehler mithilfe von Byteman. Die folgenden Fehlertypen werden unterstützt:
-
Benutzerdefinierte Ausnahmen auslösen
-
Garbage Collection auslösen
-
Methodenlatenz erhöhen
-
Rückgabewerte von Methoden ändern
-
Fehler durch Konfiguration von Byteman-Dateien auslösen
-
JVM-Druck erhöhen
Dieses Dokument beschreibt, wie Sie Chaosd verwenden, um die oben genannten JVM-Fehlertypen zu erzeugen.
Experimente im Befehlszeilenmodus erstellen
Dieser Abschnitt erklärt, wie Sie JVM-Anwendungsfehlerexperimente im Befehlszeilenmodus erstellen.
Vor der Experimenterstellung können Sie folgenden Befehl ausführen, um die von Chaosd unterstützten JVM-Fehlertypen anzuzeigen:
chaosd attack jvm -h
Das Ergebnis sieht wie folgt aus:
JVM attack related commands
Usage:
chaosd attack jvm [command]
Available Commands:
exception throw specified exception for specified method
gc trigger GC for JVM
latency inject latency to specified method
return return specified value for specified method
rule-file inject fault with configured byteman rule file
stress inject stress to JVM
Flags:
-h, --help help for jvm
--pid int the pid of Java process which needs to attach
--port int the port of agent server (default 9288)
Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID
Use "chaosd attack jvm [command] --help" for more information about a command.
Benutzerdefinierte Ausnahmen im Befehlszeilenmodus auslösen
Befehle zum Auslösen benutzerdefinierter Ausnahmen
Um Verwendung und Konfigurationsoptionen des Ausnahmebefehls anzuzeigen, führen Sie folgenden Befehl aus:
chaosd attack jvm exception --help
Das Ergebnis sieht wie folgt aus:
throw specified exception for specified method
Usage:
chaosd attack jvm exception [options] [flags]
Flags:
-c, --class string Java class name
--exception string the exception which needs to throw for action 'exception'
-h, --help help for exception
-m, --method string the method name in Java class
Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--pid int the pid of Java process which needs to attach
--port int the port of agent server (default 9288)
--uid string the experiment ID
Konfigurationsbeschreibung für benutzerdefinierte Ausnahmen
| Configuration item | Abbreviation | Description | Value |
|---|---|---|---|
class | c | The name of the Java class | string type, required |
exception | None | The thrown custom exception | string type, required |
method | m | The name of the method | string type, required to be configured |
pid | None | The Java process ID where the fault is to be injected | int type, required |
port | None | The port number attached to the Java process agent. The fault is injected into the Java process through this port number. | int type. The default value is 9288. |
uid | None | The experiment ID | string type. This item is not required to be configured, because Chaosd randomly creates one. |
Beispiel für benutzerdefinierte Ausnahmen
chaosd attack jvm exception -c Main -m sayhello --exception 'java.io.IOException("BOOM")' --pid 30045
Das Ergebnis sieht wie folgt aus:
[2021/08/05 02:39:39.106 +00:00] [INFO] [jvm.go:208] ["byteman rule"] [rule="\nRULE Main-sayhello-exception-q6nd0\nCLASS Main\nMETHOD sayhello\nAT ENTRY\nIF true\nDO \n\tthrow new java.io.IOException(\"BOOM\");\nENDRULE\n"] [file=/tmp/rule.btm296930759]
Attack jvm successfully, uid: 26a45ae2-d395-46f5-a126-2b2c6c85ae9d
Garbage Collection im Befehlszeilenmodus auslösen
Befehle zum Auslösen der Garbage Collection
Um Verwendung und Konfigurationsoptionen des GC-Befehls anzuzeigen, führen Sie folgenden Befehl aus:
chaosd attack jvm gc --help
trigger GC for JVM
Usage:
chaosd attack jvm gc [flags]
Flags:
-h, --help help for gc
Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--pid int the pid of Java process which needs to attach
--port int the port of agent server (default 9288)
--uid string the experiment ID
Konfigurationsbeschreibung für Garbage Collection
| Configuration item | Abbreviation | Description | Value |
|---|---|---|---|
pid | None | The Java process ID where the fault is to be injected | int type, required |
port | None | The port number attached to the Java process agent. The fault is injected into the Java process through this port number. | int type. The default value is 9288. |
uid | None | The experiment ID | string type. This item is not required to be configured, because Chaosd randomly creates one. |
Beispiel für Garbage Collection
chaosd attack jvm gc --pid 89345
Das Ergebnis sieht wie folgt aus:
[2021/08/05 02:49:47.850 +00:00] [INFO] [jvm.go:208] ["byteman rule"] [rule="\nRULE --gc-u0mlf\nGC\nENDRULE\n"] [file=/tmp/rule.btm012481052]
Attack jvm successfully, uid: f360e70a-5359-49b6-8526-d7e0a3c6f696
Das Auslösen der Garbage Collection ist ein einmaliger Vorgang, das Experiment erfordert keine Wiederherstellung.
Methodenlatenz im Befehlszeilenmodus erhöhen
Befehle zum Erhöhen der Methodenlatenz
Um Verwendung und Konfigurationsoptionen des Latenzbefehls anzuzeigen, führen Sie folgenden Befehl aus:
chaosd attack jvm latency --help
Das Ergebnis sieht wie folgt aus:
inject latency to specified method
Usage:
chaosd attack jvm latency [options] [flags]
Flags:
-c, --class string Java class name
-h, --help help for latency
--latency int the latency duration, unit ms
-m, --method string the method name in Java class
Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--pid int the pid of Java process which needs to attach
--port int the port of agent server (default 9288)
--uid string the experiment ID
Konfigurationsbeschreibung für Methodenlatenz
| Configuration item | Abbreviation | Description | Value |
|---|---|---|---|
class | c | The name of the Java class | string type, required |
latency | None | The duration of increasing method latency | int type, required. The unit is millisecond. |
method | m | The name of the method | string type, required |
pid | None | The Java process ID where the fault is to be injected | int type, required |
port | None | The port number attached to the Java process agent. The fault is injected into the Java process through this port number. | int type. The default value is 9288. |
uid | None | The experiment ID | string type. This item is not required to be configured, because Chaosd randomly creates one. |
Beispiel für erhöhte Methodenlatenz
chaosd attack jvm latency --class Main --method sayhello --latency 5000 --pid 100840
Das Ergebnis sieht wie folgt aus:
[2021/08/05 03:08:50.716 +00:00] [INFO] [jvm.go:208] ["byteman rule"] [rule="\nRULE Main-sayhello-latency-hlib2\nCLASS Main\nMETHOD sayhello\nAT ENTRY\nIF true\nDO \n\tThread.sleep(5000);\nENDRULE\n"] [file=/tmp/rule.btm359997255]
[2021/08/05 03:08:51.155 +00:00] [INFO] [jvm.go:94] ["submit rules"] [output="install rule Main-sayhello-latency-hlib2\n\n"]
Attack jvm successfully, uid: bbe00c57-ac9d-4113-bf0c-2a6f184be261
Rückgabewerte von Methoden im Befehlszeilenmodus ändern
Befehle zum Ändern von Methodenrückgabewerten
Um Verwendung und Konfigurationsoptionen des Rückgabewertbefehls anzuzeigen, führen Sie folgenden Befehl aus:
chaosd attack jvm return --help
return specified value for specified method
Usage:
chaosd attack jvm return [options] [flags]
Flags:
-c, --class string Java class name
-h, --help help for return
-m, --method string the method name in Java class
--value string the return value for action 'return'. Only supports number and string types.
Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--pid int the pid of Java process which needs to attach
--port int the port of agent server (default 9288)
--uid string the experiment ID
Konfigurationsbeschreibung für geänderte Rückgabewerte
| Configuration item | Abbreviation | Description | Value |
|---|---|---|---|
| class | c | The name of the Java class | string type, required to be configured |
| method | m | The name of the method | string type, required to be configured |
| value | None | Specifies the return value of the method | string type, required to be configured. Currently, the item can be numeric and string types. If the item (return value) is string, double quotes are required, like "chaos". |
| pid | None | The Java process ID where the fault is needed to be injected | int type, required to be configured |
| port | None | The port number attached to the Java process agent. The faults is injected into the Java process through this port number. | int type. The default value is 9288. |
uid | None | The experiment ID | string type. This item is not required to be configured, because Chaosd randomly creates one. |
Beispielszenario für geänderte Methodenrückgabewerte
chaosd attack jvm return --class Main --method getnum --value 999 --pid 112694
Das Ergebnis sieht wie folgt aus:
[2021/08/05 03:35:10.603 +00:00] [INFO] [jvm.go:208] ["byteman rule"] [rule="\nRULE Main-getnum-return-i6gb7\nCLASS Main\nMETHOD getnum\nAT ENTRY\nIF true\nDO \n\treturn 999;\nENDRULE\n"] [file=/tmp/rule.btm051982059]
[2021/08/05 03:35:10.820 +00:00] [INFO] [jvm.go:94] ["submit rules"] [output="install rule Main-getnum-return-i6gb7\n\n"]
Attack jvm successfully, uid: e2f204f6-4bed-4d92-aade-2b4a47b02e5d
Fehler durch Byteman-Konfigurationsdateien im Befehlszeilenmodus auslösen
Sie können Fehlerregeln in Byteman-Konfigurationsdateien definieren und diese durch Angabe des Dateipfads mit Chaosd injizieren. Zur Byteman-Regelkonfiguration siehe byteman-rule-language.
Befehle für Fehlerauslösung via Byteman-Konfiguration
Um Verwendung und Konfigurationsoptionen des Byteman-Konfigurationsbefehls anzuzeigen, führen Sie folgenden Befehl aus:
chaosd attack jvm rule-file --help
Das Ergebnis sieht wie folgt aus:
inject fault with configured byteman rule file
Usage:
chaosd attack jvm rule-file [options] [flags]
Flags:
-h, --help help for rule-file
-p, --path string the path of configured byteman rule file
Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
--pid int the pid of Java process which needs to attach
--port int the port of agent server (default 9288)
--uid string the experiment ID
Konfigurationsbeschreibung für Byteman-basierte Fehlerauslösung
| Configuration item | Abbreviation | Description | Value |
|---|---|---|---|
path | None | Specifies the path of the Byteman configuration file | string type, required |
pid | None | The Java process ID where the fault is to be injected | int type, required |
port | None | The port number attached to the Java process agent. The fault is injected into the Java process through this port number. | int type. The default value is 9288. |
uid | None | The experiment ID | string type. This item is not required to be configured, because Chaosd randomly creates one. |
Beispiel für Fehlerauslösung via Byteman-Konfiguration
Zunächst schreiben Sie basierend auf dem spezifischen Java-Programm und unter Bezugnahme auf die Byteman-Regelsprache eine Regelkonfigurationsdatei. Beispiel:
RULE modify return value
CLASS Main
METHOD getnum
AT ENTRY
IF true
DO
return 9999
ENDRULE
Speichern Sie dann die Konfigurationsdatei in der Datei return.btm. Führen Sie anschließend den folgenden Befehl aus, um Fehler zu injizieren.
chaosd attack jvm rule-file -p ./return.btm --pid 112694
Das Ergebnis sieht wie folgt aus:
[2021/08/05 03:45:40.757 +00:00] [INFO] [jvm.go:152] ["rule file data:RULE modify return value\nCLASS Main\nMETHOD getnum\nAT ENTRY\nIF true\nDO\n return 9999\nENDRULE\n"]
[2021/08/05 03:45:41.011 +00:00] [INFO] [jvm.go:94] ["submit rules"] [output="install rule modify return value\n\n"]
Attack jvm successfully, uid: 5ca2e06d-a7c6-421d-bb67-0c9908bac17a
Erhöhen der JVM-Auslastung im Befehlszeilenmodus
Befehle zum Erhöhen der JVM-Auslastung
Um die Verwendung und Konfigurationsoptionen des Befehls zum Erhöhen der JVM-Auslastung anzuzeigen, führen Sie den folgenden Befehl aus:
chaosd attack jvm stress --help
Das Ergebnis sieht wie folgt aus:
inject stress to JVM
Usage:
chaosd attack jvm stress [options] [flags]
Flags:
--cpu-count int the CPU core number
-h, --help help for stress
--mem-type int the memory type to be allocated. The value can be 'stack' or 'heap'.
Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--pid int the pid of Java process which needs to attach
--port int the port of agent server (default 9288)
--uid string the experiment ID
Konfigurationsbeschreibung zum Erhöhen der JVM-Auslastung
| Configuration item | Abbreviation | Description | Value |
|---|---|---|---|
cpu-count | None | The number of CPU cores used for increasing JVM stress | int type. You must configure one item between cpu-count and mem-type. |
mem-type | None | The type of OOM | string type. Currently, both 'stack' and 'heap' OOM types are supported. You must configure one item between cpu-count and mem-type. |
pid | None | The Java process ID where the fault is to be injected | int type, required |
port | None | The port number attached to the Java process agent. The fault is injected into the Java process through this port number. | int type. The default value is 9288. |
uid | None | The experiment ID | string type. This item is not required to be configured, because Chaosd randomly creates one. |
Beispiel zum Erhöhen der JVM-Auslastung
chaosd attack jvm stress --cpu-count 2 --pid 123546
Das Ergebnis sieht wie folgt aus:
[2021/08/05 03:59:51.256 +00:00] [INFO] [jvm.go:208] ["byteman rule"] [rule="\nRULE --stress-jfeiu\nSTRESS CPU\nCPUCOUNT 2\nENDRULE\n"] [file=/tmp/rule.btm773062009]
[2021/08/05 03:59:51.613 +00:00] [INFO] [jvm.go:94] ["submit rules"] [output="install rule --stress-jfeiu\n\n"]
Attack jvm successfully, uid: b9b997b5-0a0d-4f1f-9081-d52a32318b84
Experimente im Dienstmodus erstellen
Sie können die folgenden Anweisungen befolgen, um Experimente im Dienstmodus zu erstellen.
-
Führen Sie Chaosd im Dienstmodus aus:
chaosd server --port 31767 -
Senden Sie eine HTTP-POST-Anfrage an den Pfad
/api/attack/{uid}des Chaosd-Dienstes:curl -X POST 172.16.112.130:31767/api/attack/jvm -H "Content-Type:application/json" -d '{fault-configuration}'Für den Teil
fault-configurationim obigen Befehl müssen Sie ihn gemäß den Fehlertypen konfigurieren. Entsprechende Parameter finden Sie in den Parametern und Beispielen der einzelnen Fehlertypen in den folgenden Abschnitten.
Wenn Sie ein Experiment ausführen, denken Sie daran, die UID-Informationen des Experiments zu speichern. Wenn Sie das Experiment mit der entsprechenden UID beenden möchten, müssen Sie eine HTTP-DELETE-Anfrage an den Pfad /api/attack/{uid} des Chaosd-Dienstes senden.
Benutzerdefinierte Ausnahmen im Dienstmodus auslösen
Parameter zum Auslösen benutzerdefinierter Ausnahmen
| Parameter | Description | Value |
|---|---|---|
action | The action of the experiment | Set to "exception" |
class | The name of the Java class | string type, required |
exception | The thrown custom exception | string type, required |
method | The name of the method | string type, required |
pid | The Java process ID where the fault is to be injected | int type, required |
port | The port number attached to the Java process agent. The faults is injected into the Java process through this port number. | int type. The default value is 9288. |
uid | The experiment ID | string type. This item is not required to be configured, because Chaosd randomly creates one. |
Beispiel zum Auslösen benutzerdefinierter Ausnahmen im Dienstmodus
curl -X POST 172.16.112.130:31767/api/attack/jvm -H "Content-Type:application/json" -d '{"action":"exception","class":"Main","method":"sayhello","exception":"java.io.IOException(\"BOOM\")","pid":1828622}'
Das Ergebnis sieht wie folgt aus:
{"status":200,"message":"attack successfully","uid":"c3c519bf-819a-4a7b-97fb-e3d0814481fa"}
Garbage Collection im Dienstmodus auslösen
Parameter zum Auslösen der Garbage Collection
| Parameter | Description | Value |
|---|---|---|
action | The action of the experiment | Set to "gc" |
pid | The Java process ID where the fault is to be injected | int type, required |
port | The port number attached to the Java process agent. The fault is injected into the Java process through this port number. | int type. The default value is 9288. |
uid | The experiment ID | string type. This item is not required to be configured, because Chaosd randomly creates one. |
Beispiel zum Auslösen der Garbage Collection im Dienstmodus
curl -X POST 172.16.112.130:31767/api/attack/jvm -H "Content-Type:application/json" -d '{"action":"gc","pid":1828622}'
Das Ergebnis sieht wie folgt aus:
{"status":200,"message":"attack successfully","uid":"c3c519bf-819a-4a7b-97fb-e3d0814481fa"}
Das Auslösen der Garbage Collection ist ein einmaliger Vorgang. Das Experiment erfordert keine Wiederherstellung.
Methodenlatenz im Dienstmodus erhöhen
Parameter zum Erhöhen der Methodenlatenz
| Parameter | Description | Value |
|---|---|---|
action | The action of the experiment | Set to "latency" |
class | The name of the Java class | string type, required |
latency | The duration of increasing method latency | int type, required. The unit is millisecond. |
method | The name of the method | string type, required |
pid | The Java process ID where the fault is to be injected | int type, required |
port | The Java process ID where the fault is needed to be injected | int type, required |
uid | The experiment ID | string type. This item is not required to be configured, because Chaosd randomly creates one. |
Beispiel zum Erhöhen der Methodenlatenz im Dienstmodus
curl -X POST 172.16.112.130:31767/api/attack/jvm -H "Content-Type:application/json" -d '{"action":"latency","class":"Main","method":"sayhello","latency":5000,"pid":1828622}'
Das Ergebnis sieht wie folgt aus:
{"status":200,"message":"attack successfully","uid":"a551206c-960d-4ac5-9056-518e512d4d0d"}
Rückgabewerte einer Methode im Dienstmodus ändern
Parameter zum Ändern der Rückgabewerte einer Methode
| Parameter | Description | Value |
|---|---|---|
action | The action of the experiment | Set to "return" |
class | The name of the Java class | string type, required |
method | The name of the method | string type, required |
value | Specifies the return value of the method | string type, required. Currently, the item can be numeric and string types. If the item (return value) is string, double quotes are required, like "chaos". |
pid | The Java process ID where the fault is to be injected | int type, required |
port | The port number attached to the Java process agent. The fault is injected into the Java process through this port number. | int type. The default value is 9288. |
uid | The experiment ID | string type. This item is not required to be configured, because Chaosd randomly creates one. |
Beispiel zum Ändern der Rückgabewerte einer Methode im Dienstmodus
curl -X POST 172.16.112.130:31767/api/attack/jvm -H "Content-Type:application/json" -d '{"action":"return","class":"Main","method":"getnum","value":"999","pid":1828622}'
Das Ergebnis sieht wie folgt aus:
{"status":200,"message":"attack successfully","uid":"a551206c-960d-4ac5-9056-518e512d4d0d"}
Fehler durch Festlegen von Byteman-Konfigurationsdateien im Dienstmodus auslösen
Sie können die Fehlerregeln gemäß der Byteman-Regelkonfiguration festlegen. Weitere Informationen zur Byteman-Regelkonfiguration finden Sie unter byteman-rule-language.
Parameter zum Auslösen von Fehlern durch Festlegen von Byteman-Konfigurationsdateien
| Parameter | Description | Value |
|---|---|---|
action | The action of the experiment | Set to "rule-data" |
rule-data | Specifies the Byteman configuration data | string type, required |
pid | The Java process ID where the fault is to be injected | int type, required |
port | The port number attached to the Java process agent. The fault is injected into the Java process through this port number. | int type. The default value is 9288. |
uid | The experiment ID | string type. This item is not required to be configured, because Chaosd randomly creates one. |
Beispiel zum Auslösen von Fehlern durch Festlegen von Byteman-Konfigurationsdateien im Dienstmodus
Zunächst schreiben Sie basierend auf dem spezifischen Java-Programm und unter Bezugnahme auf die Byteman-Regelsprache eine Regelkonfigurationsdatei. Beispiel:
RULE modify return value
CLASS Main
METHOD getnum
AT ENTRY
IF true
DO
return 9999
ENDRULE
Anschließend wandeln Sie die Zeilenumbrüche in der Konfigurationsdatei in das Newline-Zeichen "\n" um und verwenden den resultierenden Text als Wert für "rule-data". Führen Sie folgenden Befehl aus:
curl -X POST 127.0.0.1:31767/api/attack/jvm -H "Content-Type:application/json" -d '{"action":"rule-data","pid":30045,"rule-data":"\nRULE modify return value\nCLASS Main\nMETHOD getnum\nAT ENTRY\nIF true\nDO return 9999\nENDRULE\n"}'
Das Ergebnis sieht wie folgt aus:
{"status":200,"message":"attack successfully","uid":"a551206c-960d-4ac5-9056-518e512d4d0d"}
JVM-Auslastung über den Dienstmodus erhöhen
Parameter zur Erhöhung der JVM-Auslastung
| Parameter | Beschreibung | Wert |
| :-- | :-- | :-- | --- |
| action | Die Aktion des Experiments | Auf "stress" setzen |
| cpu-count | Anzahl der CPU-Kerne zur Erhöhung der CPU-Auslastung | Integer-Typ. Es muss entweder cpu-count oder mem-type konfiguriert werden. |
| mem-type | Art des OOM-Fehlers | String-Typ. Derzeit werden sowohl 'stack' als auch 'heap' OOM-Typen unterstützt. Es muss entweder cpu-count oder mem-type konfiguriert werden. |
| pid | Keine | Die Prozess-ID des Java-Prozesses, in den der Fehler injiziert werden soll | Integer-Typ, erforderlich |
| port | Keine | Portnummer für den Java-Prozess-Agent. Der Fehler wird über diese Portnummer in den Java-Prozess injiziert. | Integer-Typ. Standardwert ist 9288. |
| uid | Keine | Experiment-ID | String-Typ. Muss nicht konfiguriert werden, da Chaosd automatisch eine zufällige ID generiert. |
Beispiel zur Erhöhung der JVM-Auslastung über den Dienstmodus
curl -X POST 172.16.112.130:31767/api/attack/jvm -H "Content-Type:application/json" -d '{"action":"stress","cpu-count":1,"pid":1828622}'
Das Ergebnis sieht wie folgt aus:
{"status":200,"message":"attack successfully","uid":"a551206c-960d-4ac5-9056-518e512d4d0d"}