Chaos Engineering工程实战--chaosblade

        Chaos Engineering(混沌工程),相信搞互联网的或多或少都听过,Netflix发明了Chaos Monkey,经过社区的发展回馈,慢慢行成了Chaos Engineering,当你看到这边文章的时候,相信你对混沌工程是有一丢丢想法的,要不然你也不会找到这里来,国内关于混沌工程的资料不多,多数都是讲解概念的,可借鉴的落地方案不多(但也不是没有),例如阿里的Chaosblade,搞明白国内的之后,就可以朝着国外放眼了,这里有大量Chaos Engineering的资料。

        本文就以chaosblade工具为例,来看看一个简单的Chaos Engineering怎么来落地,快速上手:chaosblade wiki,关于chaosblade的架构设计本文就不聊了,直接两个字:开干,所有操作均在/mnt/chaosblade-0.0.3下进行

blade指令

    ./blade  -h

An easy to use and powerful chaos engineering experiment toolkit

Usage:
  blade [command]

Available Commands:
  create      Create a chaos engineering experiment  #create 创建一个chaos engineering
  destroy     Destroy a chaos experiment  #destroy 销毁一个destroy,一般销毁完之后,再执行revoke子命令
  help        Help about any command  #在任何子命令后输入help可查看该子命令的用法
  prepare     Prepare to experiment  #prepare 准备一个chaos engineering实验
  query       Query the parameter values required for chaos experiments  #查询已经注册的chaos 
  revoke      Undo chaos engineering experiment preparation  #撤回注册chaos engineering
  status      Query preparation stage or experiment status  #查看注册的chaos engineering的状态
  version     Print version info

Flags:
  -d, --debug   Set client to DEBUG mode
  -h, --help    help for blade

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

    ps:其中prepare、create、destroy、revoke四个指令用的比较多,prepare是运行java程序的时候需要提前使用的一个指令,提前attach到jvm上

blade默认支持场景

    ./blade create -h

Create a chaos engineering experiment

Usage:
  blade create [command]

Aliases:
  create, c

Examples:
create dubbo delay --time 3000 --offset 100 --service com.example.Service --consumer

Available Commands:
  cpu         Cpu experiment   #cpu负载测试,还可以指定负载在哪个cpu上
  disk        Disk experiment   #disk负载测试,支持disk的read/write负载模拟,还支持模拟磁盘填充
  docker      Execute a docker experiment   #docker负载测试,支持docker的cpu、disk、network、process、remove、script等负载测试
  druid       Druid experiment   #支持druid连接池的连接满模拟
  dubbo       dubbo experiment   #支持dubbo的延迟、连接池满、异常模拟
  jvm         method   #这个支持的就多了,下面细聊
  k8s         Kubernetes experiment   #k8s负载测试,支持k8s的同期的删除测试
  mysql       mysql experiment   #支持mysql的延迟、异常模拟
  network     Network experiment   #network负载测试,支持网络的延迟、dns查询延迟、丢包、远程服务丢失等场景
  process     Process experiment   #process负载测试,支持模拟kill process的场景
  script      Script chaos experiment
  servlet     java servlet experiment   #支持servlet的延迟、异常模拟

Flags:
  -h, --help   help for create

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

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

    其中network、jvm、mysql、docker都是一些热门组件的异常模拟场景。

    下面看看jvm的,jvm支持以下五个场景:

  delay                  delay time
  outofmemoryerror       JVM out of memory
  return                 Return the specify value
  throwCustomException   throw custom exception
  throwDeclaredException Throw the first declared exception of method

        ps:其中delay、throwCustomException都是需要指定到方法级别的,如果测试人员对业务代码了解深入的话,可以利用这个特性做破坏性测试。

    看着支持的场景很多,其实在Chaosblade没出现之前,cpu、disk、network、process、k8s这些场景都是可以通过linux下面的某些命令来模拟的,如果是阿里生态系的,jvm、druid、dubbo这三个需要熟练的使用, 如果官方能提供oracle的异常场景就更好了。

blade启动注意

    blade需要和待测试的运行进程属于同一用户,且JAVA版本、JAVA_HOME要设置正确。针对系统层面的设置,则需要管理员权限。

blade模拟接口延时

    准备attach一个jvm

./blade prepare jvm --process 19761
---
{"code":200,"success":true,"result":"2679c66005a0aadd"}

        ps:2679c66005a0aadd需要记住,如果忘记也可以通过query查询

    模拟接口延迟

./blade create network delay --interface eth0 --exclude-port 22 --time 10000
---
{"code":200,"success":true,"result":"dc913ccc9a7e5ea1"}

        ps:注意针对接口的延迟需要管理员权限才能操作

    测试接口延迟

#测试前
time  curl http://192.168.1.6:8000/test/index.php -I
---
HTTP/1.1 200 
Content-Type: application/json;charset=UTF-8
Content-Length: 69
Date: Mon, 10 Jun 2019 08:35:31 GMT


real	0m0.026s
user	0m0.003s
sys	0m0.000s


#测试后
time  curl http://192.168.1.6:8000/test/index.php -I
---
curl: (7) couldn't connect to host

real	0m3.003s
user	0m0.001s
sys	0m0.003s

        ps:可以看到针对url的访问明显失败

    查看有哪些chaos实验

./blade status --type create
{
	"code": 200,
	"success": true,
	"result": [
		{
			"Uid": "dc913ccc9a7e5ea1",
			"Command": "network",
			"SubCommand": "delay",
			"Flag": "--exclude-port 45685 --debug false --help false --interface eth0 --time 10000",
			"Status": "Success",
			"Error": "",
			"CreateTime": "2019-06-10T16:36:31.072125181+08:00",
			"UpdateTime": "2019-06-10T16:36:31.107533437+08:00"
		}
	]
}

    销毁创建的chaos实验

./blade destroy dc913ccc9a7e5ea1
---
{"code":200,"success":true,"result":"command: network delay --exclude-port 22 --debug false --help false --interface eth0 --time 10000"}

    撤销chaos工程

        先查询id

./blade status --type prepare
---
{
	"code": 200,
	"success": true,
	"result": [
		{
			"Uid": "2679c66005a0aadd",
			"ProgramType": "jvm",
			"Process": "19761",
			"Port": "16698",
			"Status": "Running",
			"Error": "",
			"CreateTime": "2019-06-10T16:31:58.09072211+08:00",
			"UpdateTime": "2019-06-10T16:32:05.907016597+08:00"
		}
	]
}

        再撤销

./blade revoke 2679c66005a0aadd
---
{"code":200,"success":true,"result":"success"}

Chaosblade模型

        ps:默认的场景肯定不能完全适应你的需求,所以我们还是需要了解Chaosblade的设计模型的,看看如何自定义扩展需求场景

Chaosblade命令执行过程

       

转载于:https://my.oschina.net/guol/blog/3060265

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值