Overview

Skill Level: Beginner

Basic knowledge about object orientation and java programming

This recipe will educate about the end to end process to implement chaos monkey in spring boot micro service application

Ingredients

1. Eclipse to develop the microservice along with chaos monkey implementation.

2. Jmeter to check the performance of system.

Step-by-step

  1. What is Resilient Testing?

    One type of Non Functional Testing.
    Certifying one system ( web application, desktop application, mobile application etc.) is resilient to some extent.
    This testing is very much needed for 24*7 service apps like ecommerce, healthcare apps etc.

     

     

  2. What is microservice?

    Microservices are tiny individual services written for a particular job to be performed.
    They can talk with each other.
    In our current technological era microservices have become the base for most of the web services.

  3. Examples of Microservices

    Netflix has a widespread architecture that has evolved from monolithic to SOA.  It receives more than one billion calls every day, from more than 800 different types of devices, to its streaming-video API.  Each API call then prompts around five additional calls to the backend service.
     
    Amazon has also migrated to microservices.¬† They get countless calls from a variety of applications‚ÄĒincluding applications that manage the web service API as well as the website itself‚ÄĒwhich would have been simply impossible for their old, two-tiered architecture to handle.
     
    The auction site eBay is yet another example that has gone through the same transition.  Their core application comprises several autonomous applications, with each one executing the business logic for different function areas.

  4. What is Spring Boot?

    A framework built on top of java spring framework. So it can be called a framework of framework.
    By spring boot, java developer can create microservices with very ease by just using some simple annotations as shown below:

     springframwork

  5. What is chaos monkey?

    Chaos Monkey is a software tool that was developed by Netflix engineers to test the resiliency and recoverability of their Amazon Web Services
    This has been made opensource to integrate with various microservice technologies like node js , java spring boot microservices, python etc.
    In Simple words chaos monkey creates chaotic situation by killing or increasing latency of micro service instances so that user experience delay in the services’ response.
    The responsibility of tester is to check the performance of whole system while chaos monkey is doing these type of assaults to the microservices. That is the resilience of that system.

    chaoslogo

     

  6. How does chaos monkey work?

    It increases the response time of different microservices.
    It kills the service instances.
    By doing this type of assaults it tries to decrease the performance of whole system.

    chaosprocess

  7. How to implement Chaos Monkey in Spring boot Microservice_Step1

    Add this below lines in <dependencies> in pom.xml

    <dependency>

        <groupId>de.codecentric</groupId>

        <artifactId>chaos-monkey-spring-boot</artifactId>

        <version>2.0.1</version>

    </dependency>

  8. How to implement Chaos Monkey in Spring boot Microservice_Step2

    Add this in application.yml

    spring:

      profiles:

        active: chaos-monkey

    chaos:

     monkey:

      assaults:

       level: 5

       latencyRangeStart: 100

       latencyRangeEnd: 1000

       exceptionsActive: true

       killApplicationActive: false

      watcher:

     

       restController: true

  9. How to implement Chaos Monkey in Spring boot Microservice_Step3

    Add this in application.propertiesè

    spring.profiles.active=chaos-monkey

    That’s it. The application looks like this :

    application

  10. How to implement Chaos Monkey in Spring boot Microservice_Step4

    add these below dependency also in the pom.xml==>
    <dependency>

    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>

    </dependency>

    This dependency is to activate the actuator endpoints of spring boot framework. Actuator endpoints actually gives privilege to handle any running service from outside of the code.

  11. How to implement Chaos Monkey in Spring boot Microservice_Step5

    And then in properties file add this below configurations ==>

    management.endpoint.chaosmonkey.enabled=true
    management.endpoints.web.exposure.include=health,info,chaosmonkey

    This two lines are to activate the chaosmonkey actuator endpoints so that we can disable and enable the chaos monkey from outside the code ( by postman, ,browser etc.)

  12. How to implement Chaos Monkey in Spring boot Microservice_Step6

    Then from postman do this==>
    POST http://127.0.0.1:8094/actuator/chaosmonkey/enable

    if you are running your application on 8094 port.

     enablechaos

  13. How to implement Chaos Monkey in Spring boot Microservice_Step7

    Now be sure that chaos monkey is running good by doing this==>

    GET http://127.0.0.1:8094/actuator/chaosmonkey/status

    ensurechaos

  14. How to implement Chaos Monkey in Spring boot Microservice_Step8

    Now run the jmeter and you will see that performance is very bad and also due to the chaos exceptions some responses are bad (400,500 etc) [deviation:106]

    withchaos

     

    withchaos_2withchaos_3

     

  15. How to implement Chaos Monkey in Spring boot Microservice_Step9

    Now disable the chaos monkey by below process==>

    POST http://127.0.0.1:8094/actuator/chaosmonkey/disable

    disablechaos

  16. How to implement Chaos Monkey in Spring boot Microservice_Step10

    Now again run jmeter, you will see the service is performing well enough ==>[deviation:18]

     withoutchaos
    And all the responses are 200 ==>[everything green]

    withoutchaos_2

    Enjoy doing resilient testing with Chaos Monkey. Happy Coding and Happy Testing!

Join The Discussion