4

Preamble

We will show you a go-zero microservice example in detail through a series of articles. The whole series is divided into ten articles. The directory structure is as follows:

  1. Environment construction
  2. service split
  3. User service
  4. product service
  5. Order service
  6. payment service
  7. RPC Service Auth Authentication
  8. service monitoring
  9. Link Tracing (this article)
  10. Distributed transaction

I hope that through this series, you can quickly develop a mall system using go-zero in the Docker environment on the local machine, so that you can quickly get started with microservices.

Complete example code: https://github.com/nivin-studio/go-zero-mall

First, let's take a look at the overall service split diagram:

9.1 Jaeger Introduction

Jaeger Yes Uber A distributed tracing system developed and open source, compatible with OpenTracing API , suitable for the following scenarios:

  • Distributed trace information delivery
  • Distributed Transaction Monitoring
  • problem analysis
  • Service Dependency Analysis
  • performance optimization

The full link tracking function of Jaeger is mainly completed by three roles:

  • client : Responsible for the timing and sampling of each call point on the entire link, and send the tracing data to the local agent .
  • agent : responsible for collecting client sent tracing data, and to thrift protocol forwarded to collector .
  • collector : Responsible for collecting all agent tracing and storing them uniformly.

9.2 go-zero use Jaeger link trace

go-zero framework has already helped us implement link tracking (see: go-zero link tracking ), and the integration supports Jaeger , Zipkin these two With the link tracking reporting tool, we can visualize the complete call chain of a request, as well as the call status and performance of each link with a simple configuration.

9.2.1 Add user api service Telemetry configure

 $ vim mall/service/user/api/etc/user.yaml
 Name: User
Host: 0.0.0.0
Port: 8000

...

Telemetry:
  Name: user.api
  Endpoint: http://jaeger:14268/api/traces
  Sampler: 1.0
  Batcher: jaeger

9.2.2 add user rpc service Telemetry configure

 $ vim mall/service/user/rpc/etc/user.yaml
 Name: user.rpc
ListenOn: 0.0.0.0:9000

...

Telemetry:
  Name: user.rpc
  Endpoint: http://jaeger:14268/api/traces
  Sampler: 1.0
  Batcher: jaeger

9.2.3 add product api service Telemetry configure

 $ vim mall/service/product/api/etc/product.yaml
 Name: Product
Host: 0.0.0.0
Port: 8001

...

Telemetry:
  Name: product.api
  Endpoint: http://jaeger:14268/api/traces
  Sampler: 1.0
  Batcher: jaeger

9.2.4 Add product rpc service Telemetry configure

 $ vim mall/service/product/rpc/etc/product.yaml
 Name: product.rpc
ListenOn: 0.0.0.0:9001

...

Telemetry:
  Name: product.rpc
  Endpoint: http://jaeger:14268/api/traces
  Sampler: 1.0
  Batcher: jaeger

9.2.5 Add order api service Telemetry configure

 $ vim mall/service/order/api/etc/order.yaml
 Name: Order
Host: 0.0.0.0
Port: 8002

...

Telemetry:
  Name: order.api
  Endpoint: http://jaeger:14268/api/traces
  Sampler: 1.0
  Batcher: jaeger

9.2.6 Add order rpc service Telemetry configure

 $ vim mall/service/order/rpc/etc/order.yaml
 Name: order.rpc
ListenOn: 0.0.0.0:9002

...

Telemetry:
  Name: order.rpc
  Endpoint: http://jaeger:14268/api/traces
  Sampler: 1.0
  Batcher: jaeger

9.2.7 Add pay api Service Telemetry Configuration

 $ vim mall/service/pay/api/etc/pay.yaml
 Name: Pay
Host: 0.0.0.0
Port: 8003

...

Telemetry:
  Name: pay.api
  Endpoint: http://jaeger:14268/api/traces
  Sampler: 1.0
  Batcher: jaeger

9.2.8 add pay rpc service Telemetry configure

 $ vim mall/service/pay/rpc/etc/pay.yaml
 Name: pay.rpc
ListenOn: 0.0.0.0:9003

...

Telemetry:
  Name: pay.rpc
  Endpoint: http://jaeger:14268/api/traces
  Sampler: 1.0
  Batcher: jaeger
Tip: After the configuration is modified, the service needs to be restarted to take effect.

9.3 Use Jaeger UI view the link

  • Access /api/user/userinfo api接口

  • In the first chapter of environment construction , we integrated the Jaeger service, and made the host port --- ab6cb62f6a80358adff3a43a2f4519f5 Jaeger UI port number 16686 the host port 5000 The mapping relationship, so enter http://127.0.0.1:5000/ in the browser to access the Jaeger UI interface. Select the Search menu, select user.api a075fec67d686de828af22fdb799cfda--- in the Service drop-down box, and finally click the Find Traces button to query the --- just accessed /api/user/userinfo Link trace data of the interface.

  • Click in, you can see the link sequence diagram of this /api/user/userinfo interface, as well as service dependencies, and time-consuming.

  • The drop-down menu in the upper right corner can select different data display styles.

  • Other interface link tracking renderings

project address

https://github.com/zeromicro/go-zero

Welcome go-zero and star support us!

WeChat exchange group

Follow the official account of " Microservice Practice " and click on the exchange group to get the QR code of the community group.


kevinwan
931 声望3.5k 粉丝

go-zero作者