Adding the Zipkin server to your machine

Let's add the Zipkin server to your machine, you can create the Zipkin server application by using the following Maven Zipkin dependencies:

<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<scope>runtime</scope>
</dependency>

The preceding Maven dependencies have the Zipkin server and Zipkin UI application, but you have to enable it by using an annotation.

It will be a Spring Boot application and enable the Zipkin server by using the @EnableZipkinServer annotation in the main application class:

@SpringBootApplication
@EnableZipkinServer
public class ZipkinServerApplication {
...
}

By default, the Zipkin server will run at http://localhost:9411. The @EnableZipkinServer annotation will use it to listen for incoming spans and the http://localhost:9411 URL UI for querying.

But it doesn't need to create a Zipkin server application, you can use the built-up Zipkin application. Zipkin has a Docker image and an executable JAR of this application at https://zipkin.io/pages/quickstart.html. You just download it to your machine and run it by using the following command:

$ java -jar zipkin-server-2.8.3-exec.jar

Let's see the following screenshot after running the Zipkin application on the machine:

As you can see in the preceding screenshot, the Zipkin server is started, you can access it by navigating to http://localhost:9411 in your favorite browser:

As you can see, the Zipkin UI can be used to find traces and spans.

After adding and starting the Zipkin server, let's add the Spring Cloud Sleuth Zipkin dependency to your microservices, such as the Account and Customer services, by adding the following Maven dependency to each microservice:

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>

The preceding Zipkin starter dependency will also include the Spring Cloud Sleuth library (spring-cloud-starter-sleuth), so it doesn't require you to add it separately.

We have already discussed the Sleuth tool, it is used to generate the trace IDs and span IDs. Sleuth adds information, such as trace IDs and span IDs, to the service calls in the headers, so that the Zipkin tool and ELK can use this information.

So far, we have integrated Zipkin and Sleuth in our microservices applications. So, whenever we call customer service endpoints, Sleuth works automatically and sends this service call information to the attached Zipkin server. And Zipkin will calculate the service call latency along with some other information.

Let's see the following diagram, when we call the Customer service:

As you can see in the preceding diagram, Zipkin will store this latency information. Let's open the Zipkin dashboard after calling the customer service in the browser, as follows:

As you can see in the preceding screenshot, it has included the latency of service calls with span IDs. Let's click on the trace ID in the dashboard. It will render information regarding the trace ID:

As you can see, the preceding screenshot has information about a particular trace ID, which means a particular end-to-end transaction. You can also see the details of the trace, including all span IDs, by clicking on this row, and it will be displayed as in the following screenshot:

The preceding screenshot has more details about the trace ID for a particular end-to-end transaction of the microservices.

I hope you have learned to use the Zipkin library to analyze the latency of the service calls across the microservices in a distributed system. Sleuth passes the API call information to Zipkin.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.82.4