灾备演练--Netflix的猴子们Monkeys

2019-04-08  本文已影响0人  Wayne维基

话不多说前言

Simian Army包含以下几种Monkey

Chaos Monkey介绍

chaos-monkey-spring-boot

@Controller
@RestController
@Service
@Repository
@Component
- 通过配置激活assaults和watcher
sb-chaos-monkey-architecture.png

依赖

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>chaos-monkey-spring-boot</artifactId>
    <version>2.0.1</version>
</dependency>

启动

java -jar your-app.jar --spring.profiles.active=chaos-monkey
spring.profiles.active=chaos-monkey
chaos.monkey.enabled=true
server.port=10011
spring.application.name=chaos

spring.profiles.active=chaos-monkey
chaos.monkey.enabled=true

chaos.monkey.watcher.controller=false
chaos.monkey.watcher.restController=true
chaos.monkey.watcher.service=true
chaos.monkey.watcher.repository=false
chaos-started.jpg

进阶功能(通过Http构建)

management.endpoint.chaosmonkey.enabled=true
management.endpoint.chaosmonkeyjmx.enabled=true

# inlcude all endpoints
management.endpoints.web.exposure.include=*

# include specific endpoints
management.endpoints.web.exposure.include=health,info,chaosmonkey
ID 描述 方法
/chaosmonkey 运行chaos monkey GET
/chaosmonkey/status chaos monkey是 enable or disabled GET
/chaosmonkey/enable enable POST
/chaosmonkey/disable disable POST
/chaosmonkey/watcher 启动watcher GET
/chaosmonkey/assaults 启动 assults GET
/chaosmonkey/assaults 更新 assults POST
{
    "chaosMonkeyProperties":{
        "enabled":true
    },
    "assaultProperties":{
        "level":3,
        "latencyRangeStart":1000,
        "latencyRangeEnd":3000,
        "latencyActive":true,
        "exceptionsActive":false,
        "killApplicationActive":false,
        "watchedCustomServices":[

        ]
    },
    "watcherProperties":{
        "controller":true,
        "restController":false,
        "service":true,
        "repository":false,
        "component":false
    }
}

源码分析

位置在META-INF/spring.factories

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  de.codecentric.spring.boot.chaos.monkey.configuration.ChaosMonkeyConfiguration
可以看出是通过EnableAutoConfigurationImportSelector读取,被springboot自动加载的
@EnableConfigurationProperties({ChaosMonkeyProperties.class, AssaultProperties.class, WatcherProperties.class})

-   其中加载了一些默认配置,通过修改application.properties可以将其覆盖

-   然后在其中分别根据condition的配置加载了watcher
@Bean
    public ChaosMonkey chaosMonkey(List<ChaosMonkeyAssault> chaosMonkeyAssaults) {
        return new ChaosMonkey(settings(), chaosMonkeyAssaults, publisher());
    }
- 从ChaosMonkey跳转到实现的component

这一篇就到这里了,
源码github

上一篇 下一篇

猜你喜欢

热点阅读