Movis is a research-driven project focused on exploring practical solutions to common backend development challenges using Spring Boot. Topics include optimizing database queries, comparing EntityManager
vs JpaRepository
, leveraging JpaSpecificationExecutor
, and configuring effective monitoring with Grafana, Prometheus, Loki, and Promtail.
The Docker Compose file grafana.yml
is designed for Windows systems.
If you're using a different setup, comment out or update the volume mapping:
# E:/logs:/var/log # Update this path to match your local setup
Run the following command to start the services:
docker compose -f .\grafana.yml up -d
To enable Spring Boot logging with Loki, activate the Maven profile named grafana
:
mvn spring-boot:run -Dspring-boot.run.profiles=grafana
Open Grafana in your browser:
π http://localhost:3000
Default login credentials:
- Username:
admin
- Password:
admin
- Go to βοΈ Settings β Data Sources
- Click "Add data source"
- Select Loki
- Set the URL to:
http://loki:3100
- Click "Save & Test"
- Navigate to:
- Home β Dashboards β New Dashboard
- Select Loki as the data source
- Scroll down to Label Filters, then:
- Select
app
βmovies-app
- Use the following LogQL query:
{app="movies-app"} |= ""
- Select
- Click "Visualization Suggestion" and select "Logs"
- Use the right panel to customize the view
- Don't forget to save your dashboard! πΎ
This guide will help you set up Grafana, configure Prometheus as a data source, and create a dashboard.
Once running, Prometheus can be accessed at: π http://localhost:9090
You can use this UI to run PromQL queries and inspect collected metrics.
- Go to βοΈ Settings β Data Sources
- Click "Add data source"
- Select Prometheus
- Set the URL to:
http://prometheus:9090
- Click "Save & Test"
If Prometheus is running outside of Docker, use:
http://localhost:9090
- Navigate to:
- Home β Dashboards β New Dashboard
- Click "Add a new panel"
- Select Prometheus as the data source
- In the query editor, enter a PromQL query (example):
http_server_requests_seconds_count{uri="/actuator/prometheus"}
- Click "Run Query" to see the results
- Select a visualization type (e.g., Time Series)
- Click "Save Dashboard" and give it a name
Check the Prometheus UI at http://localhost:9090 and run queries like:
up
http_server_requests_seconds_count
If no data appears, check that your Spring Boot app is running and exposing metrics at: π http://localhost:8080/actuator/prometheus
Grafana has built-in dashboards for JVM, Spring Boot, and Prometheus. You can import one by:
- Go to Dashboards β Import
- Use the following Dashboard IDs:
- Spring Boot Metrics: 6756
If it showsN/A
, typehost.docker.internal:8080
in the "instance" field. - JVM Dashboard: 4701
- Prometheus Stats: 3662
1οΈβ£ Check If Spring Boot Exposes Metrics
π http://localhost:8080/actuator/prometheus
2οΈβ£ Verify That Prometheus is Scraping Spring Boot
π http://localhost:9090
http_server_requests_seconds_count
- Customize queries for your application
- Add alerts for critical metrics
- Explore Grafana dashboards for better visualization
Run the following commands to start the MySQL database:
cd movies/src/main/docker
sudo docker-compose -f mysql.yml up -d
Edit the configuration file:
π movies/src/main/java/resources/application.properties
Replace custom.db.address
with your Docker machine's IP address.
Retrieve all movies:
http://localhost:8080/api/movies
Use query parameters to filter results:
http://localhost:8080/api/movies?authorNameLike=falcon
http://localhost:8080/api/movies?movieTypeIn=COMEDY,HORROR
http://localhost:8080/api/movies?movieTypeIn=COMEDY,HORROR&authorNameLike=falcon
Retrieve all authors:
http://localhost:8080/api/authors
Run the following commands to add random test data (this may take time):
POST: /api/authors/seed-by-random-data/1000
POST: /api/movies/seed-by-random-data/10000
GET: /api/authors/reports/movies-count?page=0&size=10
GET: /api/authors/reports/movies-count-with-join?page=0&size=10
The implementation can be found in:
π AuthorQueryService
Performance tests were conducted in:
π BigDataTestIT
createAuthor()
,updateAuthor()
,deleteById()
are implemented in:
πAuthorControllerTestIT
- Static methods like
findByTitle()
andcountMovies()
can be used anywhere by providing anentityManager
andtransaction
. - Implemented in:
πAuthorControllerTestIT
The Specification pattern is used for filtering data using JpaSpecificationExecutor
.
It handles Enums with "IN" clause, numbers with "equals", and Strings with "LIKE".
Implemented in:
π MovieQueryService
β findByCriteria()
In π RandomMoviePicker
, the following topics are demonstrated:
- Capturing Variables:
captureMovies()
method captures variables within a lambda. - Using
Runnable
Functional Interface:ifEmpty()
executes a block of code. - Using
Consumer
Functional Interface:ifNonEmptyCapture()
processes a list of movies. - Static Factory Method Pattern:
from()
creates instances ofRandomMoviePicker
.
These concepts are applied in:
π MovieToWatchServiceImpl
β pickMoviesToWatch()
To test the implementation, call:
GET http://localhost:8080/api/movies-to-watch