当前位置:网站首页>Take you ten days to easily complete the go micro service series (IX. link tracking)

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

2022-07-05 00:58:00 Wan Junfeng, Kevin

preface

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

  1. Environment building
  2. Service split
  3. Customer service
  4. Product service
  5. Order service
  6. Payment services
  7. RPC service Auth verification
  8. Service monitoring
  9. Link tracking ( this paper )
  10. Distributed transactions

I hope this series will take you to use it locally Docker Environmental utilization go-zero Quickly develop a mall system , Let you get started with micro services quickly .

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

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

9.1 Jaeger Introduce

Jaeger yes Uber Develop and open source a distributed tracking system , compatible OpenTracing API, For the following scenarios :

  • Distributed tracking information transfer
  • Distributed transaction monitoring
  • Problem analysis
  • Service dependency analysis
  • performance optimization

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

  • client: Be responsible for the timing of each call point on the whole chain 、 sampling , And will tracing The data is sent locally agent.
  • agent: Responsible for collection client It's from tracing data , And thrift The agreement is forwarded to collector.
  • collector: Responsible for collecting all agent Reported tracing data , Unified storage .

go-zero  The framework has helped us realize link tracking ( See :go-zero Link tracking ), And the integration supports Jaeger, Zipkin These two link tracking and reporting tools , We just need a simple configuration , You can visually view the complete call chain of a request , And the call and performance of each link .

9.2.1 add to user api service Telemetry To 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 to user rpc service Telemetry To 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 to product api service Telemetry To 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 to product rpc service Telemetry To 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 to order api service Telemetry To 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 to order rpc service Telemetry To 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 to pay api service Telemetry To configure

$ 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 to pay rpc service Telemetry To 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

Tips : After configuration modification , You need to restart the service to take effect .

  • visit /api/user/userinfoapi Interface

  • stay Chapter one Environment building We integrated  Jaeger  service , And for it Jaeger UI Port number 16686 Made the host port 5000 The mapping relation of , So enter... In the browser  http://127.0.0.1:5000/  visit  Jaeger UI  Interface . choice Search menu , stay Service Select from the drop-down box user.api, Finally, click Find Traces Button , You can query the just accessed /api/user/userinfo Link tracking data of the interface .

  • Click in , You can see this /api/user/userinfo Link sequence diagram of interface , And service dependencies , And time consuming .

  • 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

Welcome to use go-zero and star Support us !

WeChat ac group

Focus on 『 Microservice practice 』 Official account and click Communication group Get community group QR code .

原网站

版权声明
本文为[Wan Junfeng, Kevin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141100091751.html