Take you ten days to easily complete the Go micro service series (IX. link tracking)

preface

We will show you a go zero micro service example in detail through a series of articles. The whole series is divided into ten articles, and the directory structure is as follows:

  1. Environment construction
  2. Service splitting
  3. User services
  4. Product service
  5. Order service
  6. Payment services
  7. RPC service Auth authentication
  8. Service monitoring
  9. Link tracking (this article)
  10. Distributed transaction

Through this series, we hope to take you to quickly develop a mall system by using the Docker environment and go zero on the machine, so that you can quickly start micro services.

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

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

9.1 Jaeger introduction

Jaeger is a distributed tracking system developed and open-source by Uber. It is compatible with OpenTracing API and is suitable for the following scenarios:

  • Distributed tracking information transmission
  • Distributed transaction monitoring
  • problem analysis
  • Service dependency analysis
  • performance optimization

Jaeger's full link tracking function is mainly completed by three roles:

  • client: it is responsible for timing and sampling each call point on the whole chain, and sending tracing data to the local agent.
  • agent: it is responsible for collecting the tracing data sent by the client and forwarding it to the collector with thrift protocol.
  • collector: responsible for collecting the tracing data reported by all agent s and storing them uniformly.

9.2 # go zero # Jaeger # link tracking

The go zero} framework has helped us realize link tracking (see: Go zero link tracking )In addition, Jaeger and Zipkin are integrated and supported. With simple configuration, we can visually view the complete call chain of a request, as well as the call status and performance of each link.

9.2.1 adding user api service Telemetry configuration

$ 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 adding user rpc service Telemetry configuration

$ 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 adding product api service Telemetry configuration

$ 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 adding product rpc service Telemetry configuration

$ 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 adding order api service Telemetry configuration

$ 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 adding order rpc service Telemetry configuration

$ 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 adding 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 adding pay rpc service Telemetry configuration

$ 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 # Jaeger UI # viewing links

  • Access / api/user/userinfo api interface

  • In the first chapter, we integrated the Jaeger Service and mapped the host port 5000 for its Jaeger UI port number 16686, so enter it in the browser http://127.0.0.1:5000/ Access the # Jaeger UI # interface. Select the Search menu and select user in the Service drop-down box API. Finally, click the Find Traces button to query the link tracking data of the / api/user/userinfo interface you just accessed.

  • Click in to see the link sequence diagram of the / api/user/userinfo interface, as well as the service dependency and time consumption.

  • Different data display styles can be selected from the drop-down menu in the upper right corner.

  • Effect drawing of other interface link tracking

Project address

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

https://gitee.com/kevwan/go-zero

Welcome to go zero and star support us!

Wechat communication group

Focus on the "micro service practice" official account and click on the exchange group to get the community community's two-dimensional code.

Keywords: bash yaml v-im jaeger

Added by kee1108 on Fri, 28 Jan 2022 07:42:39 +0200