阿里混沌工程-chaosblade工具不惑

阿里混沌工程-chaosblade工具不惑

文章目录

  • 阿里混沌工程-chaosblade工具不惑
    • 一、前言
    • 二、mysql试验
      • 1.delay试验
      • 2.throwCustomException试验
    • 三、mongodb、es、rabbitmq、rocketmq试验等
    • 四、gateway试验
      • 1.gateway试验

一、前言

阅读这篇文章之前,建议你先阅读一下 阿里混沌工程-chaosblade工具初识

[root@rabbit-node1 ~]# blade create -h
Create a chaos engineering experimentUsage:blade create [command]Aliases:create, cExamples:
blade create cpu load --cpu-percent 60Available Commands:cplus       C++ chaos experimentscpu         Cpu experimentdisk        Disk experimentdocker      Docker experimentdruid       Experiment with the Druiddubbo       Experiment with the Dubboes          ElasticSearch experiment!file        File experimentgateway     gateway experiment!hbase       hbase experiment!http        http experimentjedis       jedis experimentjvm         Experiment with the JVMk8s         Kubernetes experimentkafka       kafka experimentlettuce     redis client lettuce experimentlog         log experimentmem         Mem experimentmongodb     MongoDB experimentmysql       mysql experimentnetwork     Network experimentprocess     Process experimentpsql        Postgrelsql experimentrabbitmq    rabbitmq experimentredisson    redisson experimentrocketmq    Rocketmq experiment,can make message send or pull delay and exceptionscript      Script chaos experimentservlet     java servlet experimentstrace      strace experimentsystemd     Systemd experimenttars        tars experimentFlags:-a, --async             whether to create asynchronously, default is false-e, --endpoint string   the create result reporting address. It takes effect only when the async value is true and the value is not empty-h, --help              help for create-n, --nohup             used to internal async create, no need to config--uid string        Set Uid for the experiment, adapt to dockerGlobal Flags:-d, --debug   Set client to DEBUG modeUse "blade create [command] --help" for more information about a command.

二、mysql试验

mysql的混沌测试是基于jdbc 实现的,因此运行blade create mysql delay试验之前,通常先进行 java agent attach操作即使用blade prepare jvm --pid 16865进行agent挂载(该步骤也可省略,隐式挂载);
常用试验场景delaythrowCustomException

[root@rabbit-node1 ~]# blade create mysql -h
Mysql experiment contains delay and exception by table name and so on.Usage:blade create mysql [flags]blade create mysql [command]Available Commands:delay                delay timethrowCustomException throw custom exceptionFlags:-h, --help   help for mysqlGlobal Flags:-a, --async             whether to create asynchronously, default is false-d, --debug             Set client to DEBUG mode-e, --endpoint string   the create result reporting address. It takes effect only when the async value is true and the value is not empty-n, --nohup             used to internal async create, no need to config--uid string        Set Uid for the experiment, adapt to dockerUse "blade create mysql [command] --help" for more information about a command.

1.delay试验

[root@rabbit-node1 ~]# blade create mysql delay -h
Mysql delay experimentUsage:blade create mysql delayExamples:
# Do a delay 2s experiment for mysql client connection port=3306 INSERT statement
blade create mysql delay --time 2000 --sqltype select --port 3306Flags:--database string         The database name which used--effect-count string     The count of chaos experiment in effect--effect-percent string   The percent of chaos experiment in effect-h, --help                    help for delay--host string             The database host--javaHome string         Specify the JAVA_HOME variable to loading jre lib--offset string           delay offset for the time--pid string              The process id--port string             The database port which used--process string          Application process name--refresh                 Uninstall java agent and reload it--sqltype string          The sql type, for example, select, update and so on.--table string            The first table name in sql.--time string             delay time (required)--timeout string          set timeout for experiment in secondsGlobal Flags:-a, --async             whether to create asynchronously, default is false-d, --debug             Set client to DEBUG mode-e, --endpoint string   the create result reporting address. It takes effect only when the async value is true and the value is not empty-n, --nohup             used to internal async create, no need to config--uid string        Set Uid for the experiment, adapt to docker

先通过jps -l命令,查看需要挂载的java应用的进程号(本例中为16865

  • java应用 (部分代码截取)
spring:datasource:url: jdbc:mysql://192.168.198.1:3306/db1?serverTimezone=GMT%2B8&characterEncoding=utf8&useUnicode=trueusername: rootpassword: 123456
server:port: 8888
    @GetMapping("/mysql")public List<Map<String, Object>> mysql() {final List<Map<String, Object>> list = jdbcTemplate.queryForList("select * from test limit 5");return list;}
[root@rabbit-node1 ~]# jps -l
16865 blade-0.0.1-SNAPSHOT.jar
52074 sun.tools.jps.Jps
  • delay试验

官方示例: blade create mysql delay --time 2000 --sqltype select --port 3306(注意:执行该语句前,一定要先进行java agent挂载操作),如果你想增加更多限制如hostportdatabase,可使用如下命令:

blade create mysql delay --database db1 --host 192.168.198.1 --port 3306 --pid 16865 --sqltype select --table test --time 4000
  • 延迟测试
time curl http://localhost:8888/mysql
  • 销毁试验
blade destroy "e0b2cafeadd5ad31"
blade status --type prepare
blade revoke "9817c390d0f98b57"

2.throwCustomException试验

[root@rabbit-node1 ~]# blade create mysql throwCustomException -h
Mysql throws customer exception experimentUsage:blade create mysql throwCustomExceptionAliases:throwCustomException, tceExamples:
# Do a throws customer exception experiment for mysql client connection port=3306 INSERT statement
blade create mysql throwCustomException --exception java.lang.ExceptionFlags:--database string            The database name which used--effect-count string        The count of chaos experiment in effect--effect-percent string      The percent of chaos experiment in effect--exception string           Exception class inherit java.lang.Exception (required)--exception-message string   Specify exception message for exception experiment, default value is chaosblade-mock-exception-h, --help                       help for throwCustomException--host string                The database host--javaHome string            Specify the JAVA_HOME variable to loading jre lib--pid string                 The process id--port string                The database port which used--process string             Application process name--refresh                    Uninstall java agent and reload it--sqltype string             The sql type, for example, select, update and so on.--table string               The first table name in sql.--timeout string             set timeout for experiment in secondsGlobal Flags:-a, --async             whether to create asynchronously, default is false-d, --debug             Set client to DEBUG mode-e, --endpoint string   the create result reporting address. It takes effect only when the async value is true and the value is not empty-n, --nohup             used to internal async create, no need to config--uid string        Set Uid for the experiment, adapt to docker
  • throwCustomException试验
blade prepare jvm  --pid 16865
blade create mysql throwCustomException --exception java.lang.Exception
  • 异常测试
time curl http://localhost:8888/mysql
  • 销毁试验
blade destroy "191262659a5b664e"
blade status --type prepare
blade revoke "66870aef759696ec"

三、mongodb、es、rabbitmq、rocketmq试验等

用法同mysql,不同的target支持的参数有细微区别,例如:
blade create es throwCustomException --exception java.lang.Exception --index index2
blade create rocketmq throwCustomException --exception java.lang.Exception --topic=xx --consumerGroup=xx

blade create mongodb -h
blade create es -h
blade create rabbitmq -h
blade create rocketmq-h

四、gateway试验

 blade create gateway -h

1.gateway试验

[root@rabbit-node1 ~]# blade create gateway delay -h
SpringCloud Gateway delay experimentUsage:blade create gateway delayExamples:
# Do a delay 2s experiment for SpringCloud Gateway forward operations
blade create gateway delay --requestPath /gateway/path --time 2000Flags:--effect-count string     The count of chaos experiment in effect--effect-percent string   The percent of chaos experiment in effect-h, --help                    help for delay--javaHome string         Specify the JAVA_HOME variable to loading jre lib--offset string           delay offset for the time--pid string              The process id--process string          Application process name--refresh                 Uninstall java agent and reload it--requestPath string      The gateway path which used (required)--time string             delay time (required)--timeout string          set timeout for experiment in secondsGlobal Flags:-a, --async             whether to create asynchronously, default is false-d, --debug             Set client to DEBUG mode-e, --endpoint string   the create result reporting address. It takes effect only when the async value is true and the value is not empty-n, --nohup             used to internal async create, no need to config--uid string        Set Uid for the experiment, adapt to docker
  • delay试验
blade prepare jvm  --pid 16865
blade create gateway delay --requestPath /gateway/path --time 2000

套路一样不写了 😅😅😅


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部