/spring-boot-restcontroller

Sample code for a RestController in Spring using Swagger

Primary LanguageJava

Spring Boot @RestController Example with Chaos Monkey Enabled in Spring Application Properties

Description

This project contains the sample code used in The Practical Developer Blog. It's a Spring Boot application with one plain Java object (SpanishGreeting) and a Spring Controller SpanishGreetingController.

The main goal of the project is to show how to write a @RestController in Spring Boot and include documentation with Swagger.

How does it work?

You can use the endpoints behind http://localhost:8082/spanish-greetings. If you append /random to a GET request you'll receive a random Spanish greeting (which are actually hard-coded). You can also GET them by id (only from 1 to 3). To create a new one, you need to perform a POST operation.

Actually, much better if you just start the application and navigate to http://localhost:8082/swagger-ui.html. There you'll find a nice API documentation thanks to Swagger. Moreover, you can play with it.

Swagger Documentation

Upon Succesful Initialization of Chaos Monkey you should see something like this :

image

In addition to the end points and controller, chaos testing can be done as shown using postman for the endpoints exposed under actuator:

image image image image image image

Change the Assaults Configuration to invoke Methods within the Application:

image

Confirm Response: image

Initiate the Attack Vector: image

Sample Response 1: image

Sample Response 2: image

Confirmation of Runtime Exceptions Activated: image

Logs Confirming Chaos Monkey Bringing Down Application: image

Before changing the attack vector assaults configuration is default as shown : image

Logs: image

After changing attack vector: image

Initating Attack: image

Confirmation of Shutdown via Logs : image

#CPU Attack wit hMemory Assaults: image

image

Configuration changes to pom.xml and prometheus.yml :

pom.xml:

image

prometheus.yml:

image

Prometheus UI showing targets up :

image

CPU attack assault in Spring Boot Application:

image

Spike in Cpu Utilization seen in Prometheus:

image

Injected Latency attack :

image image

After disabling chaos

image