Spring Cloud study notes-012

  • Distributed Service Tracing: Spring Cloud Sleuth

  With the development of business, the scale of the system will become larger and larger, and the calling relationship between microservices will become more and more complicated. Usually, a request initiated by the client will go through multiple different microservice calls in the back-end system to generate the final request result. In a complex micro-service architecture system, almost every front-end request will form a complex distribution If there is a high latency or error in any dependent service in each link, it may cause the final request to fail. At this time, for each request, the tracking of full-link calls becomes more and more important. Implementing the tracking of request calls can help us quickly find the root cause of errors and monitor and analyze performance bottlenecks on each request link.

1. Preparation, build some basic facilities and applications:

  ◆  Service registration center: demo-eureka-server, I won't go into details here, just use the project built before.

  ◆  Microservice application: demo-trace-1, which implements a REST interface/trace-1, which will trigger a call to the trace-2 application after calling this interface. details as follows: 

  1). Create a basic sprigboot application named demo-trace-1, add web, eureka, ribbon dependencies.

  2). Create the application main class:

  

  3). Create the application.yml file in the src\main\resources directory:

  

  4). Create a basic sprigboot application named demo-trace-2, add web, eureka, ribbon dependencies.

  5). Create the application main class:

  

  6). Create the application.yml file in the src\main\resources directory:

  

  7). Start the demo-eureka-server, demo-trace-1 and demo-trace-2 applications. Test the trace-1 interface and confirm that the return is correct:

  

2. After completing the preparations, add the service trace function to the above trace-1 and trace-2. Add related dependencies to the pom.xml files of trace-1 and trace-2:

3. Restart trace-1 and trace-2, call the trace-1 interface again, and observe the trace-1 console and some log information. These elements are an important part of implementing distributed service tracing:

 

  • Integration with Zipkin

  Zipkin is an open source project of Twitter, which is based on Google Dapper. It can be used to collect the trace data of the request link on each server, and use the REST API interface it provides to assist in querying the trace data to realize the monitoring program of the distributed system, so as to timely detect the problem of increased delay in the system and solve the problem Identify the source of system performance bottlenecks. In addition to the development-oriented API interface, it also provides convenient UI components to help us intuitively search for tracking information and analyze request link details, such as querying the processing time of each user request within a certain period of time.

  Zipkin's main 4 core components:

  ◆  Collector: The collector component, which mainly processes the tracking information sent from the external system, and converts the information into the Span format internally processed by Zipkin to support subsequent storage, analysis, display and other functions.

  ◆  Storage: The storage component, which mainly handles the trace information received by the collector, and stores the information in the memory by default. This storage policy can also be modified to store tracking information in the database by using other storage components.

  ◆  RESTful API: API component, which is mainly used to provide external access interface. For example, showing work information to clients, or accessing external systems for monitoring, etc.

  ◆  Web UI: UI components, upper-layer applications based on API components. Through UI components, users can query and analyze tracking information conveniently and intuitively.

1. Create a maven project, select quickstart for the skeleton, and name it demo-zipkin-server

2. Add related dependencies:

3. Create a startup class:

4. Create the application.properties file in the src\main\resources directory:

5. Start the project (Note: JDK1.8 is required), and visit the main page:

6. The trace-1 and trace-2 projects before the transformation. Add relevant dependencies to both projects:

7. Add the configuration information of Zipkin Server to the configuration files of the two projects:

8. Restart the two projects, access the trace-1 interface, and observe the zipkin page:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325946972&siteId=291194637