1 distributed tracking system

As a large number of companies refactor individual applications into microservices, the responsibility for operations personnel becomes even greater. It is not easy to quickly diagnose problems and find performance bottlenecks from more complex architectures with more applications. As a result, a number of diagnostic and analytical systems for DevOps have emerged, with three main ones:

  • Centralized Log System (Logging)
  • Centralized Measurement (Metrics)
  • Distributed Tracking System (Tracing)

The three interweave and overlap as follows:

The mature frameworks on the technology stack are,

Logging: Log4j, ELK, etc.

Metrics: Prometheus, InfluxDB, Grafana, etc

Tracing: Jaeger, Zipkin, etc.

Dapper, a Large-scale Distributed Systems Tracing Infrastructure, has been rapidly developing since Google published the article Dapper. Tracing system generally has three core steps: code burial, data storage, query display.

The tide of history is rolling, the waves are sweeping, and the current ones are Jaeger and Zipkin.

2 OpenTracing

Because of the rapid development of Tracing technology, in order to solve the compatibility problem, there is OpenTracing specification. It is a lightweight, standardized layer that connects applications, libraries, and tracking systems.

Advantages of OpenTracing:

(1) OpenTracing has entered CNCF (Cloud Native Computing Foundation, slogan is to adhere to and integrate open source technology to orchestrating containers as part of the microservices architecture), is providing a unified concept and data standard for global distributed tracking.

(2) By providing platform independent and vendor independent API, OpenTracing enables developers to easily add and change the implementation of tracking system.

2.1 Related Concepts

Trace: A transaction tracing description across a distributed system, which is actually a directed acyclic graph composed of many spans.

Span: named and timed call operations, such as an Http GET request; Spans have nested relationships, and if a request calls another service, subspans are generated.

Tag: a set of tags consisting of key-value pairs. The key-value type must be string. It can carry a lot of useful information, such as request method, request URL, return status code, and so on.

Log: a set of Span logs.

2.2 Implementation of OpenTracing

Jaeger is an open source distributed tracking system from Uber that is compatible with the OpenTracing API. The structure is as follows:

Zipkin is an open source distributed tracking system created by Twitter.

3 Practical integration

This article takes Springboot as a Web project, integrating Jaeger and Zipkin, respectively.

3.1 Preparing for the Springboot project

The Controller in the project provides two endpoints, Tracing and open; Tracing is invoked by the code when open is accessed.

@RestController public class TracingController { @Autowired private RestTemplate restTemplate; @Value("${server.port}") private int port; @RequestMapping("/tracing") public String tracing() throws InterruptedException { Thread.sleep(100); return "tracing"; } @RequestMapping("/open") public String open() throws InterruptedException { ResponseEntity<String> response = restTemplate.getForEntity("http://localhost:" + port + "/tracing", String.class); Thread.sleep(200); return "open " + response.getBody(); }}Copy the code

In order to make it easier to see the call duration information, the delay thread.sleep () has been added to the code.

Configure the port and service name of the Web application:

server.port=80
spring.application.name=opentracing-demoCopy the code

3.2 integrated Jaeger

3.2.1 Springboot integration

Reference dependencies:

<dependency> <groupId>io.opentracing.contrib</groupId> <artifactId>opentracing-spring-jaeger-web-starter</artifactId> The < version > 3.1.1 < / version > < / dependency >Copy the code

Configure connection properties:

opentracing.jaeger.enabled=true
opentracing.jaeger.udp-sender.host=localhost
opentracing.jaeger.udp-sender.port=6831Copy the code

Docker runs Jaeger

For convenience, use Docker to run Jaeger:

Docker pull jaegertracing/all-in-one:1.17  docker run -d --name jaeger \ -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \ -p 5775:5775/udp \ -p 6831:6831/udp \ -p 6832:6832/udp \ -p 5778:5778 \ -p 16686:16686 \ -p 14268:14268 \ -p 14250:14250 \ -p 9411:9411 \ Jaegertracing/all - in - one: 1.17Copy the code

The information about the ports is as follows:

3.2.3 Running and Accessing the UI

After starting the Web application and Jaeger, access the service:

http://localhost/open

http://localhost/tracing

You can check the Traces on the Jaeger UI at http://localhost:16686/, set the query criteria and click ‘Find Traces’ to see what they are:

After selecting a Trace point, you can see the detailed information, which is very helpful for our analysis. The details are as follows:

3.3 Zipkin

3.3.1 Springboot integration

Referencing dependencies:

<dependency> <groupId>io.opentracing.contrib</groupId> <artifactId>opentracing-spring-zipkin-web-starter</artifactId> The < version > 0.1.4 < / version > < / dependency >Copy the code

Configure connection information:

opentracing.zipkin.enabled=true
opentracing.zipkin.http-sender.base-url=http://localhost:9412/Copy the code

Docker runs Zipkin

Run a Zipkin instance with Docker:

Docker run -d -p 9412:9411 openzipkin/ Zipkin :2.21Copy the code

Since the local port 9411 is already occupied by Jaeger’s Docker instance, change to 9412.

3.3.3 Running and Accessing the UI

After starting the Web application and Zipkin, access the service:

http://localhost/open

http://localhost/tracing

Visit Zipkin UI interface, http://localhost:9412/zipkin/, set up the query conditions and then click the query, you can see the Trace information, specific as follows:

Select a Trace and click on it. Again, you can see a lot of details, which are not shown here.

4 summarizes

This article explains in detail two implementations of Springboot integration OpenTracing through code cases (Jaeger and Zipkin), demo code can be concerned about the public account background reply “OpenTracing” to obtain.

Reference links:

OpenTracing concept: OpenTracing. IO/docs/overvi…

Jaeger architecture diagram: www.jaegertracing.io/docs/1.17/a…

Zipkin. IO /pages/ Archi…

Jaeger Docker information: www.jaegertracing.io/docs/1.17/g…

Zipkin Docker information: hub.docker.com/r/openzipki…

Jaeger Spring Integration project: github.com/opentracing…

Zipkin Spring Integration project: github.com/opentracing…


Welcome to follow the public number < pumpkin slow say >, will continue to update for you…

Read more, share more; Write more. Organize more.