카오스 엔지니어링 툴: 로컬에서는 경험하기 힘든 운영 환경에서 발생하는 아래와 같은 이슈를 미리 확인해 볼 수 있는 툴이다.

  • 네트워크 지연
  • 서버 장애
  • 디스크 오작동
  • 메모리 누수

 

Chaos Monkey Spring Boot

codecentric.github.io/chaos-monkey-spring-boot/

 

Chaos Monkey for Spring Boot

This project provides a Chaos Monkey for Spring Boot and will try to attack your running Spring Boot App.

codecentric.github.io

애노테이션들이 붙어있는 Bean들의 메소드에 public이 붙여져 있다면 오른쪽의 공격들을 해 볼 수 있다. 응답 지연을 한 번 만들어 보자

 

 

 

먼저 의존성을 추가해주고 profile에 활성화를 시켜주어야 한다.

// 스프링 부트용 카오스 멍키
implementation 'de.codecentric:chaos-monkey-spring-boot:2.0.2'

// 스프링 부트 운영 툴로, 런 타임 중에 카오스 멍키 설정 변경 가능/헬스체크/로그 레벨 변경/매트릭스 데이터 조회 등 다양하게 사용 가능
implementation 'org.springframework.boot:spring-boot-starter-actuator'
//application.properties

//카오스 멍키 활성화
spring.profiles.active=chaos-monkey

//스프링 부트 Actuator 엔드 포인트 활성화
management.endpoint.chaosmonkey.enabled=true
management.endpoints.web.exposure.include=health,info,chaosmonkey

 

 

Repository 애노테이션이 붙은 곳에 카오스 멍키를 적용해 보기 위해서는 application.properties 파일에 아래 부분이 추가되어야 한다.

//application.properties
chaos.monkey.watcher.repository=true

 

그 다음 httpie를 이용하여 http 명령어를 보내서 활성화 시키면 된다.

httpie.io/

 

HTTPie – command-line HTTP client for the API era

CLI HTTP that will make you smile. JSON and sessions support, syntax highlighting, wget-like downloads, plugins, and more.

httpie.io

  • 카오스 멍키 활성화: http post localhost:8080/actuator/chaosmonkey/enable
  • 카오스 멍키 상태 확인: http localhost:8080/actuator/chaosmonkey/status
  • 카오스 멍키 watcher 설정 확인: http localhost:8080/actuator/chaosmonkey/watchers
    • 주의) watcher를 끄는 것은 바로 반영 되지만, 활성화의 경우는 런타임에 반영되지 않는다. 따라서 watcher의 변경은 properties 파일에서 하는 것이 좋다.

 

지연 공격은 아래와 같은 명령어를 입력하면 된다.

http POST localhost:8080/actuator/chaosmonkey/assaults level=3 latencyRangeStart=2000 latencyRangeEnd=5000 latencyActive=true
  • level=3: 3번 요청할 때마다 1번씩 공격하도록
  • latencyRangeStart=2000 latencyRangeEnd=5000: 2초부터 5초 내로 응답을 지연 시켜라
  • latencyActive=true: 지연 공격을 활성화 하도록

 

 

위와 같이 애플리케이션에 공격을 할 수도 있지만, 애플리케이션에 에러가 발생하는 상황을 재현할 수도 있다.

http POST localhost:8080/actuator/chaosmonkey/assaults level=3 latencyActive=false exceptionsActive=true exception.type=java.lang.RuntimeException

 

 

더 많은 예시는 아래를 참고하자

codecentric.github.io/chaos-monkey-spring-boot/2.1.1/#_examples

 

Chaos Monkey for Spring Boot Reference Guide

Chaos Monkey for Spring Boot can be customized to your planned experiment. You can decide which attacks you want to run and which parts of your application should be attacked. Except for the Watcher, you can also influence the behavior of the Chaos Monkey

codecentric.github.io

 

+ Recent posts