How eugenemsv/spring-micrometer-observation works
Project type and purpose
• This is a single-service Spring Boot demo application whose primary purpose is to showcase Micrometer’s new “Observation” API in action. It exposes a simple user CRUD REST API and pushes metrics to Prometheus for scraping.
File structure
• Top-level artifacts:
• Dockerfile, pom.xml, Maven wrappers → Java build + containerization
• compose/ → local Docker Compose setup for the service + Prometheus
• bruno/ → HTTP test scripts / Postman collection for exercising the API
• src/main/java/com/github/eugenemsv/spring/micrometer/observation → the service code
• Application entrypoint & runner
• ObservationConfiguration (Micrometer setup)
• Controller, Service, Observation handlers & context classes
• src/main/resources/application.yaml → service configuration (ports, metrics path)
README
• Confirms Java 21 + Docker + Docker Compose
• Instructs how to launch the microservice container + Prometheus, and to drive the APIs via the “bruno” collection
Main components
a. Client:
– Bruno test scripts or any HTTP client → issues REST calls to the service on port 8080
b. Spring Boot Microservice (single container):
– HTTP layer: UserController
– Business layer: UserService, UserCreation, etc.
– Observation layer (cross-cutting):
• ObservationConfiguration bean → configures Micrometer Observation registry
• LoggingObservationHandler, UserDeletionObserver → implement Observer pattern hooks
• UserObservationContext → context passed to handlers
– Metrics endpoint: /actuator/prometheus (or default Micrometer endpoint)
c. Prometheus (running in a separate container via Docker Compose):
– Scrapes the microservice’s metrics endpoint on port 8080 at regular intervals
– Serves a UI on port 9090 for querying metrics
Relationships and interactions
• Client → HTTP request → Microservice’s UserController → UserService → returns response
• At each observation point, the Observation API invokes registered handlers (logger, custom observers)
• Micrometer collects metrics (counters, timers) and exposes them on the /actuator/prometheus endpoint
• Prometheus container → scrapes metrics → stores time-series data → serves queries via its UI
Architectural patterns & design principles
• Layered architecture (Controller → Service → Data/Observation handlers)
• Observer pattern for measurement instrumentation
• Externalized configuration (application.yaml, ObservationConfiguration)
• Containerization & orchestration via Docker + Docker Compose (one network, two containers)
Technologies & frameworks
• Java 21, Spring Boot
• Spring Micrometer Observation API
• Micrometer registry → Prometheus
• Docker, Docker Compose
• Maven