阿里混沌工程-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 experiment

Usage:
  blade create [command]

Aliases:
  create, c

Examples:
blade create cpu load --cpu-percent 60

Available Commands:
  cplus       C++ chaos experiments
  cpu         Cpu experiment
  disk        Disk experiment
  docker      Docker experiment
  druid       Experiment with the Druid
  dubbo       Experiment with the Dubbo
  es          ElasticSearch experiment!
  file        File experiment
  gateway     gateway experiment!
  hbase       hbase experiment!
  http        http experiment
  jedis       jedis experiment
  jvm         Experiment with the JVM
  k8s         Kubernetes experiment
  kafka       kafka experiment
  lettuce     redis client lettuce experiment
  log         log experiment
  mem         Mem experiment
  mongodb     MongoDB experiment
  mysql       mysql experiment
  network     Network experiment
  process     Process experiment
  psql        Postgrelsql experiment
  rabbitmq    rabbitmq experiment
  redisson    redisson experiment
  rocketmq    Rocketmq experiment,can make message send or pull delay and exception
  script      Script chaos experiment
  servlet     java servlet experiment
  strace      strace experiment
  systemd     Systemd experiment
  tars        tars experiment

Flags:
  -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 docker

Global Flags:
  -d, --debug   Set client to DEBUG mode

Use "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 time
  throwCustomException throw custom exception

Flags:
  -h, --help   help for mysql

Global 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

Use "blade create mysql [command] --help" for more information about a command.

1.delay试验

[root@rabbit-node1 ~]# blade create mysql delay -h
Mysql delay experiment

Usage:
  blade create mysql delay

Examples:
# Do a delay 2s experiment for mysql client connection port=3306 INSERT statement
blade create mysql delay --time 2000 --sqltype select --port 3306

Flags:
      --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 seconds

Global 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=true
    username: root
    password: 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 experiment

Usage:
  blade create mysql throwCustomException

Aliases:
  throwCustomException, tce

Examples:
# Do a throws customer exception experiment for mysql client connection port=3306 INSERT statement
blade create mysql throwCustomException --exception java.lang.Exception

Flags:
      --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 seconds

Global 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 experiment

Usage:
  blade create gateway delay

Examples:
# Do a delay 2s experiment for SpringCloud Gateway forward operations
blade create gateway delay --requestPath /gateway/path --time 2000



Flags:
      --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 seconds

Global 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

套路一样不写了

你可能感兴趣的:(系统,工具,软件,混沌工程,chaosblade)