15 Star 2 Fork 3

openEuler / chaosArsenal

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

chaosArsenal故障注入工具

工具简介

chaosArsenal是深信服开源的一款linux系统下通用的可靠性测试工具,通过在系统中模拟软/硬件故障,验证系统在遇到可能发生故障时的抵御能力或帮助发现系统中可能存在的漏洞。chaosArsenal专注于对linux系统软硬件故障场景模拟,契合分布式系统中对基础硬件、操作系统、中间件、业务应用等稳定性测试的强烈需求。当前开源版本覆盖的故障场景以通用、常见为主,共开源了30+的故障模式模拟能力(如下图),覆盖50多个故障场景,具体的故障模式信息、原理以及命令示例可以参考chaosArsenal工具使用手册.md。

输入图片说明

特点

  • 核心设计思想为简单易用,可实现快速部署上线,工具解压即可使用。

  • 支持多种原子故障注入能力,如CPU、内存、网络、文件系统、进程、磁盘、PCIE等多种软硬件场景。

  • 良好的拓展能力,可以根据实际业务需求快速添加自定义原子故障注入能力,实现能力拓展。

  • 支持多种调用接口, 支持cli和http两种控制接口,满足多种用户场景需求。

软件架构

chaosArsenal软件架构说明

输入图片说明

chaosArsenal工具整体架构主要分为接口层、逻辑层和原子能力。

  • ​接口层:

    提供故障注入、故障清除、故障查询等接口,支持cli和http两种方式调用。

    • cli 部分采用cobra框架,初始化root命令之后,通过解析arsenal-spec-1.0.0.json配置文和输入参数补全完整命令。
    • http部分采用openApi设计,用swagger生成http服务端代码,需要先将后台server服务端启动,再执行相应接口操作,启动方式参考“OpenAPI调用->启动server服务端”。
  • 逻辑层:

    ​逻辑层主要是用来处理接口层下发的命令,对命令进行解析,解析故障模式、故障注入参数等信息,并根据配置文件中相关信息,进行原子故障注入命令的拼接和故障注入任务执行操作,该过程会记录操作日志,并将故障注入信息写在数据库中。

    ​其中日志模块、数据库、配置文件下面会介绍相关信息。

  • 原子能力:

    原子能力是具体执行故障注入的各领域故障注入能力集,chaosArsenal v1.0.0版本开源oshardware领域的部分能力。

编译

依赖软件

Go 1.18.x以及以上。

编译环境

Linux系统(已验证系统ubutnu、Centos)。

快速构建

直接在Makefile所在目录下执行make命令,编译生成执行文件路径output/chaosArsenal/。

使用说明

OpenAPI调用

arsenal可以根据配置文件中参数可选/必选、参数个数、参数名等信息进行参数合法性校验。

默认HTTP端口

​ 如果未指定http端口则默认的服务端端口为9095

启动server服务端
  • 不带任何参数启动server服务端,默认的服务端口为 http://127.0.0.1:9095

    ./arsenal server start
    
  • ipport启动server服务端

    ./arsenal server start --host=10.103.176.172 --port=9095
  • 只带ip启动server服务端,默认端口为9095

    ./arsenal server start --host=10.103.176.172
  • 关闭server服务端

    ./arsenal server stop --signal stop
注入

​ 注入命令的所有参数放置在http请求头,params为传入某个故障模式的所有参数。

  • 单参数

    curl -X 'POST' 'http://10.103.176.172:9095/arsenal/v1/faults' -H "Content-Type: application/json" -d '{"class": "os", "domain": "file", "fault-mode": "lost", "params": {"path":"/home/curtis/work/arsenal-os/kk.sh"}}'
  • 多参数

    curl -X 'POST' 'http://10.103.176.172:9095/arsenal/v1/faults' -H "Content-Type: application/json" -d '{"class": "os", "domain": "file", "fault-mode": "corruption", "timeout": "10s", "params": {"path":"/home/curtis/work/arsenal-os/kk.sh", "offset": "2", "length": "3"}}'
  • timeout可选参数

    curl -X 'POST' 'http://10.103.176.172:9095/arsenal/v1/faults' -H "Content-Type: application/json" -d '{"class": "os", "domain": "file", "fault-mode": "corruption", "timeout": "10s", "params": {"path":"/home/curtis/work/arsenal-os/kk.sh", "offset": "2", "length": "3"}}'

timeout参数格式

pattern: ^(?:(\d+d):)?(?:(\d+h):)?(?:(\d+m):)?(?:(\d+s))?$

​ 说明:天、小时、分钟、秒,可进行任意组合使用,以:分割。

清理

​ 根据注入时返回的uuid来清理已经注入的命令。

curl -X 'DELETE' 'http://10.103.176.172:9095/arsenal/v1/faults/5d81e8f58ef7e8a1'	
查询
  • 匹配单一字段

    curl -X 'GET' 'http://10.103.176.172:9095/arsenal/v1/faults?uuid=5d81e8f58ef7e8a1'
  • 匹配多个字段

    curl -X 'GET' 'http://10.103.176.172:9095/arsenal/v1/faults?uuid=5d81e8f58ef7e8a1&domain=file'

CLI命令调用

注入
  • 常规命令

    ./arsenal inject os file corruption --path /home/curtis/work/arsenal-os/kk.sh --length 3 --offset 2
  • timeout参数

    timeout参数用来做延时故障自动清理操作。

    ./arsenal inject os file corruption --path /home/curtis/work/arsenal-os/kk.sh --length 3 --offset 2 --timeout 1m:30s

    timeout参数格式

    pattern: ^(?:(\d+d):)?(?:(\d+h):)?(?:(\d+m):)?(?:(\d+s))?$

    说明:天、小时、分钟、秒,可进行任意组合使用,以:分割。

清理
  • cli命令完整命令清除。

    ./arsenal remove os file corruption --path /home/curtis/work/arsenal-os/kk.sh --length 3 --offset 2
  • 根据uuid参数清理。

    根据uuid在数据库中查找对应表项,获得故障注入信息。

    ./arsenal remove --uuid 5d81e8f58ef7e8a1
查询
  • 匹配单一字段。

    ./arsenal query --uuid 5d81e8f58ef7e8a1
  • 匹配多个字段。

    ./arsenal query --uuid 5d81e8f58ef7e8a1 --domain file

cli命令补全

./arsenal completion bash

sqlite数据库

chaosArsenal工具中使用sqlite数据库记录故障注入信息,用于工具对故障注入对象的重复注入检查和故障恢复,也方便用户对已注入故障的查询操作等。数据库名为arsenal.db文件。

sqlite数据库字段信息

​ 数据库中字段及其类型如下:

   	"id" INTEGER PRIMARY KEY AUTOINCREMENT,
	"UUID" VARCHAR(32) UNIQUE,
	"interactive_mode" VARCHAR NOT NULL,
	"class" VARCHAR NOT NULL,
	"domain" VARCHAR NOT NULL,
	"fault_mode" VARCHAR NOT NULL,
	"object" VARCHAR NOT NULL,
    "flags" VARCHAR,
    "private" VARCHAR,
	"proactive_cleanup" BOOL,
    "status" VARCHAR NOT NULL,
    "inject_time" VARCHAR NOT NULL,
	"update_time" VARCHAR NOT NULL

​ 数据库中字段信息介绍:

  • id 数据库表索引。
  • UUID 故障注入时产生的16位uuid。
  • interactive_mode 交互模式,数据库中记录故障相关操作的交互方式,当前存在两种模式clihttp
  • class 故障类别,比如操作系统故障、硬件故障、容器故障等
  • domain 故障的作用域,比如说processfile等,表示故障所属的域。
  • fault_mode 具体的故障模式。
  • object 记录故障注入的对象。
  • flags 记录传入的所有参数,格式示例--path /home/curtis/work/arsenal-os/kk.sh
  • private 私有数据区,用在timeout的场景,cli场景下用于记录后台执行进程的pidtimeout延迟清理的时间。http场景用于记录延迟清理的时间。
  • status 当前故障的状态,当前设计存在三个状态,injected表示故障注入处于生效状态,removed表示故障已经清理,successed表示故障已经注入且不需要清理。
  • inject_time 故障注入的时间
  • update_time 数据库相关表项的更新时间,当前仅用于故障清理的场景。

sqlite数据库表项示例

​ 以下示例为通过故障查询命令获取到的数据库中已注入故障的信息展示。

{
    "UUID": "2d303aea4d2326e4",
    "InteractiveMode": "http",
    "class": "os",
    "Domain": "file",
    "FaultMode": "lost",
    "Object": "/home/curtis/work/arsenal-os/kk.sh",
    "Flags": "--path /home/curtis/work/arsenal-os/kk.sh",
    "Private": "",
    "ProactiveCleanup": true,
    "Status": "Removed",
    "InjectTime": "2023-11-23T02:39:40.184Z",
    "UpdateTime": "2023-11-23T02:39:49.334Z"
}

sqlite数据库表项清理

​ 注:当arsenal.db中有效数据库表项大于1000000条时,清理状态为RemovedSucceed的数据表项。

配置文件

JSON配置文件说明

arsenal-spec-1.0.0.json用于配置每个故障模式模拟时用到的配置信息,比如故障模式描述、执行文件信息、故障注入/清除参数等,大家在使用chaosArsenal工具框架添加新的故障注入能力时会涉及到配置arsenal-spec-1.0.0.json文件

{
    "version": "v1.0",	
    "class": {
      "os": {
        "shortDesc": "Fault injection for operating system",
        "longDesc": "Fault injection for operating system",
        "domain": {
          "file": {
            "executor": "arsenal-os",
            "shortDesc": "File reference fault",
            "longDesc": "File reference fault",
            "faultTypes": {
              "readonly": {
                "shortDesc": "file readonly",
                "longDesc": "File readonly",
                "object": "path",
                "commands": {
                  "inject": {
                    "blockExecution": true
                  },
                  "remove": {
                    "blockExecution": true
                  }
                },
                "flags": {
                  "path": {
                    "usage": "file path",
                    "shortHand": "p",
                    "required": true
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  • object

    • NA

      当故障注入对象未知时,object可以填写为NA,比如说系统panic,不需要指定故障注入对象。

    • faultType

      object可以填写为故障模式名,意味着一种故障模式同一时间只能存在一个故障。

    • 指定flags中的某个参数

      object可以填写为flags中的某个参数名,工具会根据这个参数对象来判断是否重复注入多个故障。

  • commands

    其中injectremove字段可以添加自定义命令,如下所示:

    "inject": {
        "blockExecution": true,
        "command": "arsenal-xxx inject xxx $arg1 $arg2"
    },
    • 通用接口会在输入的flags中找到arg1arg2的值,并将$arg1$arg2替换成对应的值,替换之后的命令arsenal-xxx inject xxx arg1_value arg2_value
    • 通用接口会在$arsenal_pacakge/bin/文件夹下查找原子故障注入工具arsenal-xxx
    • blockExecution为阻塞执行字段,true则阻塞执行,arsenal会等待原子命令返回后再退出,timeout时间为15s,超过15s则会上报执行失败;false则非阻塞执行,arsenal不会等待原子命令返回,直接退出。
  • 其他字段 参考数据库相关字段。

日志文件备份

​ 日志路径$arsenal_pacakge/logs/operations.log

Logger.Formatter = &logrus.TextFormatter{
    TimestampFormat:  "2006/01/02 15:04:05",
    DisableSorting:   false,
    QuoteEmptyFields: true,
}

Logger.SetOutput(&lumberjack.Logger{
    Filename:   operationsLogPath,
    MaxSize:    1024, // megabytes
    MaxBackups: 10,
    MaxAge:     28,   // days
    Compress:   true, // 是否压缩日志文件
    LocalTime:  true, // 是否使用本地时间
})
  • 日志时间戳的格式为2006/01/02 15:04:05
  • 最大的日志文件size设定为1G
  • 最大的备份文件数为10个。
  • 备份日志的保留最长的时间为28天。
  • 对备份的日志文件进行压缩。

能力扩展

新增故障注入能力时,需要在arsenal-spec-1.0.0.json配置文件中增加对应的配置信息,详见如下标记信息,对于arsenal-spec-1.0.0.json文件中特殊字段的描述见“配置文件->JSON配置文件说明”;再将对应的执行文件放在$arsenal_pacakge/bin/路径下。

{
    "version": "v1.0",	
    "class": {
      "os": {   ## chaosArsenal目前定义两类故障,分别是os和hardware,如果需要新增一个,那么需要修改源码,或是联系我们,;如果不需要,无需关心。
        "shortDesc": "Fault injection for operating system",
        "longDesc": "Fault injection for operating system",
        "domain": {
          "file": {   ## 命名一个新的作用域
            "executor": "arsenal-os",   ## 指定$arsenal_pacakge/bin/下执行文件名
            "shortDesc": "File reference fault",  ## 对作用域进行简短描述
            "longDesc": "File reference fault",   ## 对作用域进行详细描述
            "faultTypes": {
              "readonly": {   ## 新增的故障模式名称
                "shortDesc": "file readonly",   ## 对新增的故障模式进行简短描述
                "longDesc": "File readonly",    ## 对新增的故障模式进行详细描述
                "object": "path",  ## 选取一个参数进行重复注入对象鉴别信息
                "commands": {
                  "inject": {  
                    "blockExecution": true  ## 故障注入时选择阻塞或非阻塞执行
                  },
                  "remove": {
                    "blockExecution": true   ## 故障清除时选择阻塞或非阻塞执行
                  }
                },
                "flags": {
                  "path": {  ## 故障注入所需参数名
                    "usage": "file path", ## 参数描述
                    "shortHand": "p",  ## 参数简写
                    "required": true   ## 参数是否必选
                  }
                }
              }
            }
          }
        }
      }
    }
  }

FAQ

故障清理规则

  • cli只能清理通过cli注入的故障。
  • http只能清理通过http注入的故障。

二进制文件存放规则

  • /bin/ - - 用来存放项目所需的二进制文件。

  • /bin/third_party_tools - - 用来存放第三方的二进制文件。

关联文档

chaosArsenal工具使用手册

开源许可

chaosArsenal使用的Apache 2.0开源协议。

缺陷&建议

​ 非常欢迎提交工具中存在的缺陷、问题,以及您对于工具使用过程中的建议,或者是您合入的新的故障注入功能,都可以通过issues提交给我们。

​ 您也可以通过以下方式联系我们:

​ 邮箱: chaos-arsenal@sangfor.com.cn

参与贡献

chaosArsenal在持续建设阶段,欢迎感兴趣的同学一起参与贡献。

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

A toolkit for verifying system stability by simulating software and hardware failures in Linux systems. 展开 收起
Go 等 2 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/openeuler/chaosArsenal.git
git@gitee.com:openeuler/chaosArsenal.git
openeuler
chaosArsenal
chaosArsenal
master

搜索帮助