Developer: Sathish Raghu
This application is used to convert integer into Roman Numerals. Technologies used in this project are
- Java
- Spring
- SpringBoot
- Junit
- Powermock
- Swagger
- Docker/Docker-compose
- Elastic Search
- LogStash
- Kibana
- Prometheus
- Grafana
Prerequisites:
- Java 8
- Maven 3
- Docker
- Docker-Compose
- The following ports[8200, 9200, 9300, 3000, 5601, 5000, 9600, 9090,8080] should NOT be used since it will be used by various containers of this demo application
Logs Flow
- Application logs are sent to the logstash pipeline via TCP Connection
- These logs are then sent to ElasticSearch with the configured index - logstash*
- Kibana is used to visualize the logs by connecting to elasticsearch
APM Metrics Flow
- Elastic APM Agent is installed along with the spring boot application
- APM Server is also installed to capture the metrics from the apm agents
- APM Server then connects to elastic search to store all the metrics.
- Kibana is again used to visualize all the metrics.
- The APM Server and the springboot applications are created using docker compose.
JVM Metrics Flow
- Spring Boot application exposes /actuator/prometheus endpoint for exposing various JVM Metrics
- Prometheus scrapes the metrics from the application based on the configured frequency
- Grafana, the visualization platform is used to display all the metrics using different dashboards.
To install and validate the application please follow the instructions below
- Git Clone
git clone https://github.com/rsathish29/NumberConverter.git
cd NumberConverter
- Pre-requisites Java, Maven, Docker & Docker-Compose are installed in the system
java -version
mvn -v
docker version
docker-compose version
- Perform Maven Build to generate the maven artifact JAR File
mvn clean install
- After the build is successful, cd into the docker folder
cd docker
- Create the docker containers for ELK Stack using docker compose command
docker-compose -f docker-compose.yml up -d --build
- Verify if the containers for the ELK Stack is running. 7 Containers[Elastic Search, Logstash, Kibana,APM Server, SpringBootApp, Prometheus, Grafana ] should be running.
docker-compose -f docker-compose.yml ps
Name Command State Ports
-----------------------------------------------------------------------------------------------------------------------------------------------
spring_boot_elk_demo_apm_1 /usr/local/bin/docker-entr ... Up 0.0.0.0:8200->8200/tcp
spring_boot_elk_demo_elasticsearch_1 /usr/local/bin/docker-entr ... Up (healthy) 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp
spring_boot_elk_demo_grafana_1 /run.sh Up 0.0.0.0:3000->3000/tcp
spring_boot_elk_demo_kibana_1 /usr/local/bin/kibana-docker Up 0.0.0.0:5601->5601/tcp
spring_boot_elk_demo_logstash_1 /usr/local/bin/docker-entr ... Up 0.0.0.0:5000->5000/tcp, 5044/tcp, 0.0.0.0:9600->9600/tcp
spring_boot_elk_demo_prometheus_1 /bin/prometheus --config.f ... Up 0.0.0.0:9090->9090/tcp
spring_boot_elk_demo_springbootapp_1 /bin/sh -c java -javaagent ... Up 0.0.0.0:8080->8080/tcp
-
Repeat step#6 until the all containers are UP & elasticSearch is healthy(since it takes time to bootup ~1minute)
-
Spring security is enabled for the spring boot application [userId:welcome, password:Hello@123]
-
Verify the health of the spring boot application using the browser[Use the credentials provided in step#8]
{"status":"UP"}
- Verify if Kibana endpoint is accessible.
- Verify if Swagger is up and running(Use Credentials from Step#8 if prompted)
- Verify if Grafana endpoint is accessible.(User: admin, Password: Hello@123)
This application is a spring boot rest application that exposes rest API for numeric to Roman Numeral conversion
After everything starts, you can enter the url in the browser :
Test Scenarios to validate the API
GET /romannumeral?query= ~> {"error":{"code":100,"description":"Input cannot be empty"}} [400]
GET /romannumeral?query=a ~> {"error":{"code":101,"description":"Invalid Input data, expected input is Integer. Range 1-3999"}} [400]
GET /romannumeral?query=5 ~> {"result":"V"} [200 OK]
GET /romannumeral?query=18 ~> {"result":"XVIII"} [200 OK]
GET /romannumeral?query=18908 ~> {"error":{"code":101,"description":"Invalid Input data, expected input is Integer. Range 1-3999"}} [400]
Junit Test condition written
Intellij/Eclipse IDE :
Run -> ConversionControllerTest
- testConvertIntegerToRomanNumeral_Success (Positive Scenario)
- testConvertIntegerToRomanNumeral_Failure (Negative Scenario -> Invalid input)
Run -> RomanConversionServiceTest
- testIntegerToRomanNumeral (Positive Scenario, since all the negative scenarios will be handled in controller layer)
Run -> ConversionValidatorTest
- testParseInt_EmptyString (Negative Scenario -> empty input)
- testParseInt_InvalidCharacter (Negative Scenario -> non numeric)
- testParseInt_InputOutOfRange (Negative Scenario -> number out of range)
- testParseInt_SuccessScenario(Positive Scenario)
Integration Test condition written
Intellij/Eclipse IDE :
Run -> ConversionIntegrationTest
- testconvertIntegerToRomanNumeral_EmptyInput (Negative Scenario -> empty input)
- testconvertIntegerToRomanNumeral_InvalidInput (Negative Scenario -> non numeric)
- testconvertIntegerToRomanNumeral_InputOutOfRange (Negative Scenario -> number out of range)
- testconvertIntegerToRomanNumeral_Success(Positive Scenario)
Additional Springboot Actuator Metrics Monitoring Endpoints
http://localhost:8080/actuator
http://localhost:8080/actuator/health
http://localhost:8080/actuator/loggers
http://localhost:8080/actuator/heapdump
http://localhost:8080/actuator/threaddump
http://localhost:8080/actuator/prometheus
http://localhost:8080/actuator/metrics
http://localhost:8080/actuator/metrics/{requiredMetricName}
Steps to Check the application logs
- Open the following Kibana link in browser
-
In order to view the application logs, index pattern has to be created.
-
Configure Index pattern using this link
-
Key in the index pattern as logstash* [make sure the asterisk is added to the end]and click Next Step
-
Select any option in the dropdown and click the create index pattern.
-
By default, the apm-* index pattern might be selected. Please change it to logstash* pattern.
-
After making this change, the application logs should be displayed on this page. Change Time range to last 15 minutes.
Steps to Monitor Metrics of application
- Open the APM Metrics of the application in Kibana using the link
- Click on the Conversion-Service to view the application APM Metrics
- Change the time window[top right] to last 15 minutes (or) 30 minutes to see the graphs
Steps to Monitor JVM Metrics of application
- Open the Grafana Visualization Tool
- Login Credentials
username : admin
password : Hello@123
- After successful login, you should be seeing the home page as given below.
- JVM Dashboard is already preconfigured that displays various JVM Metrics. Goto to Search and search for JVM and click the dashboard - JVM(Micrometer).
- The dashboard looks something like this. Try changing the time duration from 24 hours to 15 mins or 30 mins.
Stop & Delete the containers
docker-compose -f docker-compose.yml down
docker system prune
verify containers are stopped and deleted
docker-compose -f docker-compose.yml ps
- Spring
- SpringBoot
- Swagger
- Docker
- Elastic Search
- LogStash
- Kibana
- Prometheus
- Grafana
- Spring Boot Documentation
- Docker Documentation
- Docker compose Documentation
- Logstash Documentation
- ElasticSearch Documentation
- Kibana Documentation
- Prometheus Documentation
- Grafana Documentation
- Swagger UI
TIP: You can use Docker Desktop Mac or Docker Desktop Windows to run application