Skip to content

Spring Boot demo for observability and traceability in a microservices environment. This repository contains examples of tracing and metric recopilation using Zipkin and Prometheus ingested Micrometer metrics respectively using Spring Boot libraries.

Notifications You must be signed in to change notification settings

hdmsantander/microservices-ops-demo

Repository files navigation

Microservices OPS demo

This repository holds a Spring Boot OPS demo with the following components:

  • Two microservices that perform requests to the Swagger's PetStore and comunicate with each other using HTTP requests and events using Spring Cloud Stream.
  • A ZipKin server that register traces and dependencies from the microservices operations, provided by Spring Cloud Sleuth.
  • A Prometheus server that polls the microservices to register metrics gathered from Spring Boot's actuator.
  • A Kafka cluster to comunicate the microservices and the tracer.

The demo can be started by executing the following command:

./start.sh

The Zipkin server, Prometheus server and Kafka cluster can be started standalone by running:

docker-compose -f docker-compose-minimal.yml up

Query microservice

Query microservice

This microservice performs queries to the inventory microservice and the pet shop API. It supports the following operations:

  • GET /v1/inventory This operation queries the inventory endpoint of the inventory microservice and returns the result.
  • GET /v1/pet This operation queries the list of pets from the pet shop API and returns the results.
  • POST /v1/pet/{id}/adopt This operation performs the "adoption" of a pet from the shop. It requires a valid ID from the pet shop and it triggers an adoption event, which is consumed by the inventory microservice, which then in turn emits an event.
  • GET /v1/orders This operation queries the service's database to get a list of all the orders currently registered in the system. The orders are created from events wich the inventory microservice emits.

The Swagger page is accesible at http://localhost:8080/swagger-ui.html

Inventory microservice

Inventory microservice

This microservice performs queries to the pet shop API. This service is used by the query service to perform some queries. It supports the following operations:

  • GET /v1/inventory This operation queries the inventory endpoint of the pet shop API and returns the result. It is intended to be used by the query microservice.

It also performs a scheduled query of the inventory of the pet shop API to "update" the inventory of the shop in the microservice ecosystem. The service performs a query of orders (generated randomly as integers in the range of 1-10) to the orders endpoint of the pet shop API, triggering an event if the order exists, this event is consumed by the query microservice which in turn updates the entity in question in its database.

The Swagger page is accesible at http://localhost:8079/swagger-ui.html

Prometheus server

Prometheus service

The prometheus server is accesible at http://localhost:9090

Example of metrics reported

Here are some examples of the metrics registered.

Orders updated in total

In the OrderService.java there is a section of code that updates a Counter style metric.

if (responseEntity.getStatusCode().is2xxSuccessful()) {
  log.info("Request was successful! Emitting event to update orders!");
  meterRegistry.counter("orders.updated").increment();
  orderEventService.send(responseEntity.getBody());
}

Orders updated

Time taken to adopt a pet

In the PetService.java there is an annotation that enables a Timer style metric for the method that performs pet adoptions.

@Timed(value = "pet.query.time", description = "Time taken to query and return the pet shop list for all pets")

Orders updated

Amount of orders in the system

In the PetShopOrderService.java there is a Gauge style metric that reports the size of the list containing all the orders currently in the query system's database.

private AtomicDouble orderCount = new AtomicDouble();

	public List<PetShopOrder> getAllOrders() {

		List<PetShopOrder> orders = StreamSupport.stream(petShopOrderRepository.findAll().spliterator(), false)
				.collect(Collectors.toList());

		orderCount.set(orders.size());

		meterRegistry.gauge("orders.size", orderCount);

		return orders;

	}

Orders updated

Zipkin server

Zipkin server

The Zipkin server is accesible at http://localhost:9411

Example of traces registered

Here are some examples of the traces registered.

Scheduled order retrieval

The inventory microservice performs a scheduled retrieval of the orders in the pet shop API. If it finds an order, it emits an event that the query microservice consumes to update its database.

Refresh orders

Pet adoption

The query microservice performs a GET of the pet ID to the pet shop API, and if the ID of the pet exists it emits an event which in turn is consumed by the inventory microservice.

Adoption

Kafka server

Kafka server

An interface to see the topcs and events found in the kafka server is accesible at http://localhost:3030

About

Spring Boot demo for observability and traceability in a microservices environment. This repository contains examples of tracing and metric recopilation using Zipkin and Prometheus ingested Micrometer metrics respectively using Spring Boot libraries.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published