Springcloud Combat-sleuth

Source: Internet
Author: User

Spring-cloud-sleuth is one of the components of spring Cloud, enabling a distributed tracking solution for Springcloud applications that is compatible with Zipkin, Htrace, and log-based tracking, Tracing the problem of the MicroServices Rest service invocation link, the Zipkin is exposed, and spring cloud provides spring-cloud-sleuth to facilitate the integration of Zipkin implementations.

Why is there a need for Distributed Link tracking Springcloud-sleuth?

With the distributed system becoming more and more complex, one of your requests sent past, the various microservices between the jump, there may be a request one day too much pressure, a request in the past did not respond, a request to rely on three or four services, but you do not know which service comes out of the problem, Do I need to trace the micro-service at this time? Monitoring the initiation of a request from the service between the transfer between the process, I'd better record how long each of the time, once the problem, we can be targeted to optimize, is to increase the node, reduce the pressure, or service continue to split, make logic simpler point? This time Springcloud-sleuth integrated Zipkin can help us solve these service tracking problems.

The following is an explanation of the Springcloud-sleuth part of the name from the official Springcloud document:

Span: A basic unit of work, for example, sending an RPC in a new Span is equivalent to sending a response request to rpc,span through a 64-bit ID that uniquely identifies the trace with another 64-bit ID, and Span has other data information, such as a summary , timestamp event, key value comment (tags), span ID, and progress ID (usually IP address)
Span is constantly starting and stopping, while recording time information, when you create a span, you must stop it at some point in the future.
Trace: a tree-like structure consisting of a series of spans, for example, if you are running a distributed Big Data project, you may need to create a Trace.
Annotation: used to record the existence of an event in a timely manner, some of the core notes used to define the start and stop of a request are:

1.CS-Client Sent-Clients initiate a request, this annotion describes the beginning of this span

2.SR-Server Received-the service side gets the request and is ready to start processing it, if its SR minus CS Timestamp can get network delay

3.SS-Server Sent-annotations indicate the completion of the request processing (when the request is returned to the client), if the SS minus the SR timestamp can get the processing request time required by the service side

4.CR-Client Received-Indicates the end of span, the client has successfully received a reply from the server, and if the CR minus CS timestamp can get the client to get reply from the server all the time required

Visualization of Span and the Trace the system will be viewed together with Zipkin annotations such as:

each color of a note represents a span (7 spans-from A to the G ). If you see a message like this:


Trace Id == dclient Sent

This means that the current span Trace amount of-id set to X , Span-Number set to D . It also issues events sent by the client .

This way, the visualization of the parent/child relationship of spans will look like this:

Purpose

In the following sections, the examples in the above image are taken into account.

distributed tracking and Zipkin

Total 7 x spans . If you look at traces in Zipkin, you'll see this number in the second track:

However, if you select a specific trace, you will see 4 spans :

Why is there a difference between 7 and 4 spans in this case?

    • 2 spans from the http:/start scope. It has a server receive (SR) and server Send (SS) comment.

    • 2 spans from Service1 to service2 to Http:/foo The RPC call for the endpoint. It has client send (CS) and client receive (CR) comments in the Service1 context. It also has server receive (SR) and server Send (SS) comments in Service2 . has 2 physical spans, but they form 1 logical spans related to RPC calls.

    • 2 spans from Service2 to service3 to Http:/bar The RPC call for the endpoint. It has client send (CS) and customer receive (CR) comments on Service2 . It also has the server receive (SR) and server Send (SS) comments on the service3 side. has 2 physical spans, but they form 1 logical spans related to RPC calls.

    • 2 spans from Service2 to service4 to Http:/baz The RPC call for the endpoint. It has client send (CS) and customer receive (CR) comments on Service2 . It also has a server receive (SR) and server Send (SS) comment on the service4 side. has 2 physical spans, but they form 1 logical spans related to RPC calls.

So if we calculate the spans , http:/start There are 1 calls from service1 service2 ,2( service2 ) calls service3 and 2 ( service2 ) service4 . a total of 7 spans.

logically, we see Total spans info: 4 , because we have 1 x The span associated with the incoming request service1 and the 3 spans associated with the RPC call.

Next, a demonstration of spring-cloud-sleuth to facilitate the integration of the Zipkin implementation is as follows:

First of all, our two service provider Provider1,provider2 modules in the previous article, as well as the feign modules, need to introduce the following dependencies:

<dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId> spring-cloud-sleuth-zipkin</artifactid>            <version>1.3.  0. release</version>        </dependency>        <dependency>            <groupId> Org.springframework.cloud</groupid>            <artifactId>spring-cloud-starter-sleuth</artifactId>            <version>1.3. 0. Release</version>        </dependency>

Here also to explain, here to Provider1 and Provider2 module and feign module replacement Springcloud version number, if not to change, will not start up, the replacement version is as follows

<dependencyManagement>        <dependencies>            <dependency>                <groupId> Org.springframework.cloud</groupid>                <artifactId>spring-cloud-dependencies</artifactId>                <version>dalston sr4</version>                <type>pom</type>                <scope>import</ scope>            </dependency>        </dependencies>    </dependencyManagement>

The configuration for the Provider1 is then modified, as follows:

#端口号server: Port:8080#Eureka实例名, the clusters are identified by each other Spring:application:name:hello-Service Zipkin:Base-url:http://localhost:9400Enabledtrue#服务跟踪消息收集率, 1 is collected on behalf of each article,0. 1 represents a collection of 10, if not configured, with a default percentage of # sleuth:# sampler:# percentage:0.3Eureka: #客户端 client: #注册中心地址 service-url:defaultZone:http://localhost:8888/eureka/,http://localhost: 8889/eureka/

The

Then makes the configuration file for the Provider2 module to be modified, with the following code:

  #端口号server: port:  8081   #Eureka实例名, the cluster recognizes Spring:application:name:hello -service Zipkin: base -url:http:localhost:9400  #服务跟踪消息收集率, 1 is collected for each article, 0  .1 represents a collection of 10, if not configured, there is a default percentage of # sleuth:# sampler:# percentage:  0.3  eureka: #客户端 client: #注册中心地址 Service - url:defaultzone:http:  // localhost:8888/eureka/,  http://localhost  :8889/eureka/ 

The configuration of the feign module is modified as follows:

Server:port:8083spring:application:name:feign-Consumer Zipkin:Base-url:http://localhost:9400Eureka:client:service-url:defaultZone:http://localhost:8888/eureka/,http://localhost: 8889/eureka/Hystrix:command:default: execution:isolation:thread:timeoutinMilliseconds: theribbon:connecttimeout: -#如果想对单独的某个服务进行详细配置, as follows Hello-service:ribbon:connectTimeout: -

Then create a new submodule under the original aggregation project called the Springcloud-sleuth module, such as:

The dependencies to be introduced are as follows:

<dependency>            <groupId>io.zipkin.java</groupId>            <artifactid>zipkin-server</ artifactid>            <version>2.4.  0</version>        </dependency>        <dependency>            <groupid>io.zipkin.java</ groupid>            <artifactId>zipkin-autoconfigure-ui</artifactId>            <version>2.4 . 0</version>        </dependency>

The configuration file for the Sleuth module is as follows:

Server:   9400 Spring:  application:    name:zipkin-server

The Sleuth module startup class is as follows:

@SpringBootApplication @enablezipkinserver  Public class sleuthapplication {    publicstaticvoid  main (string[] args) {        Springapplication.run (sleuthapplication. class , args);}    }

It then launches two Eureka registries, two provider1,provider2 modules, 1 feign modules, and 1 sleuth modules, such as:

First enter the sleuth and Zipkin integrated link Tracking graphical interface as seen:

Then in the feign to show the call two Provider1 and Provider2 module services, Http://localhost:8083/consumer more than a few times F5, make multiple requests, because the service trace message is a collection rate, 1 for each article is collected, 0.1 represents a collection of 10, if not configured, with a default percentage, so multiple requests are required to ensure that the tracked messages can be collected. As follows:

Then go to the Zipkin console to view the link call, as follows:

Here I choose Feign-consumer for the demo, and then click Find, as follows:

The point here is that, for example, Feign-consumer 100% and a blue stripe parcel indicate the success rate of the call, the Red bar package indicates a failure and an unexpected error occurred.

Then click on one of the call services, enter to see the details as follows:

The following is a demonstration of the error message, which I take directly from the official documentation, as follows:

Zipkin allows you to visualize errors in the trace. when an exception is thrown and is not captured, we set the appropriate label on the span where the Zipkin can be correctly colored. You can see a trace of red in the breadcrumb list. This is because an exception was thrown.

If you click on the track, you'll see a similar picture

Then, if you click on one of the spans, you will see the following

Springcloud Combat-sleuth

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.